Skip to content

Instantly share code, notes, and snippets.

@amunim
Created Jun 9, 2022
Embed
What would you like to do?
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