Skip to content

Instantly share code, notes, and snippets.

@amunim
Created June 9, 2022 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amunim/f5e4e2faed6bbda611c70d7e14931738 to your computer and use it in GitHub Desktop.
Save amunim/f5e4e2faed6bbda611c70d7e14931738 to your computer and use it in GitHub Desktop.
Import all Flagsmith flags as enum with description
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Net.Http" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" #>
<#@ assembly name="Newtonsoft.Json" #>
<#@ assembly name="Microsoft.CSharp" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Net.Http" #>
<#@ import namespace="Newtonsoft.Json.Linq" #>
namespace YOURNAMESPACE
{
public enum AllFlags
{
<#
HttpClient client = new HttpClient();
HttpRequestMessage msg = new HttpRequestMessage(new HttpMethod("GET"), "https://api.flagsmith.com/api/v1/flags/");
msg.Headers.Add("X-Environment-Key", "XXXXXXXXXXXX"); //replace with your environment key
var result = client.SendAsync(msg).Result.Content.ReadAsStringAsync().Result;
dynamic obj = JArray.Parse(result);
foreach(var flag in obj)
{
#>
<# if(!string.IsNullOrEmpty((string)flag.feature.description))
{
#>
///<summary>
/// <#= flag.feature.description #>
///</summary>
<#
}
#>
<#= flag.feature.name #>,
<#
}
#>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment