growthbook-c-sharp 1.0.6

dotnet add package growthbook-c-sharp --version 1.0.6                
NuGet\Install-Package growthbook-c-sharp -Version 1.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="growthbook-c-sharp" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add growthbook-c-sharp --version 1.0.6                
#r "nuget: growthbook-c-sharp, 1.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install growthbook-c-sharp as a Cake Addin
#addin nuget:?package=growthbook-c-sharp&version=1.0.6

// Install growthbook-c-sharp as a Cake Tool
#tool nuget:?package=growthbook-c-sharp&version=1.0.6                

growthbook banner with csharp logo

growthbook-c-sharp

Powerful feature flagging and A/B testing for C# apps using GrowthBook

nuget badge for 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

  1. Install GrowthBook

    dotnet add package growthbook-c-sharp
    
  2. Declare features

    
    var staticFeatures = new Dictionary<string, Feature>
        {
            {"firstFeature", new Feature{ DefaultValue = true}},
            {"secondFeature", new Feature{ DefaultValue = false}}
        };
    
  3. Create a context and add the features

    var context = new Context
    {
        Enabled = true,
        Url = "",
        Features = staticFeatures
    };
    
  4. Create the GrowthBook object with the context

    using GrowthBook;
    //...
    
    var GrowthBook = new GrowthBook.GrowthBook(context);
    
  5. 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:

  1. 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; }
    }
    
  2. 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);
    }
    
  3. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.0.6 20,885 7/6/2024
1.0.5 48,370 4/10/2024
1.0.4 108 4/10/2024
1.0.3 107 4/10/2024
1.0.2 17,373 2/19/2024
1.0.0 7,000 1/29/2024
0.2.0 134,870 11/9/2023
0.1.2 210 11/9/2023
0.0.7 110,617 10/23/2023
0.0.6 343,326 7/7/2022
0.0.5 474 7/7/2022
0.0.4 485 7/1/2022