growthbook-c-sharp
1.0.4
See the version list below for details.
dotnet add package growthbook-c-sharp --version 1.0.4
NuGet\Install-Package growthbook-c-sharp -Version 1.0.4
<PackageReference Include="growthbook-c-sharp" Version="1.0.4" />
paket add growthbook-c-sharp --version 1.0.4
#r "nuget: growthbook-c-sharp, 1.0.4"
// Install growthbook-c-sharp as a Cake Addin #addin nuget:?package=growthbook-c-sharp&version=1.0.4 // Install growthbook-c-sharp as a Cake Tool #tool nuget:?package=growthbook-c-sharp&version=1.0.4
growthbook-c-sharp
Powerful feature flagging and A/B testing for C# apps using GrowthBook
Table of contents
Usage examples
This library is based on the GrowthBook SDK specs and should be compatible with the usage examples in the GrowthBook docs. For a more complete set of examples involving usage within ASP.Net Core, take a look at the C# examples in the GrowthBook examples repository.
Down below you'll find two basic examples on how the package works.
Basic
Install GrowthBook
dotnet add package growthbook-c-sharp
Declare features
var staticFeatures = new Dictionary<string, Feature> { {"firstFeature", new Feature{ DefaultValue = true}}, {"secondFeature", new Feature{ DefaultValue = false}} };
Create a context and add the features
var context = new Context { Enabled = true, Url = "", Features = staticFeatures };
Create the
GrowthBook
object with the contextusing GrowthBook; //... var GrowthBook = new GrowthBook.GrowthBook(context);
Check whether a feature is enabled
GrowthBook.IsOn("firstFeature") // true GrowthBook.IsOn("secondFeature") // false
Loading feature definitions from an API
Because feature definitions are typically loaded from API calls or cache, Json.NET objects are used to represent arbitrary document types such as Attributes, Conditions, and Feature values.
To load your features from the GrowthBook API use the following example:
Create a result model for the API response
public class FeaturesResult { public HttpStatusCode Status { get; set; } public IDictionary<string, Feature>? Features { get; set; } public DateTimeOffset? DateUpdated { get; set; } }
call the endpoint and deserialize result
var url = "YOUR_GROWTHBOOK_URL/api/features/YOUR_API_KEY"; var response = await client.GetAsync(url); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); var featuresResult = JsonConvert.DeserializeObject<FeaturesResult>(content); }
Construct a context and initialize GrowthBook
var GrowthBook = new GrowthBook.GrowthBook( new Context { Enabled = true, Url = "", Features = featuresResult.Features, } );
Generic getters
To make it easier to deal with Feature values, generic getter functions are provided for the following:
- Experiment:
GetVariations<T>()
- ExperimentResult:
GetValue<T>()
- Feature:
GetDefaultValue<T>()
- FeatureResult:
GetValue<T>()
- Feature Rule:
GetVariations<T>()
- GrowthBook:
GetFeatureValue<T>(string key, T fallback)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on growthbook-c-sharp:
Package | Downloads |
---|---|
Growthbook.FeatureManagement
Integrate Growthbook with Microsoft.FeatureManagement. |
GitHub repositories
This package is not used by any popular GitHub repositories.