How do you create an enum using values from a list? So far the code retrieves a list of templates available for the Text draw object. I know it's not best practice to create an enum dynamically, however, it would make the user experience of the indicator more straightforward.
I've done it in the past by selecting an account for a parameter using AccountNameConverter.
[TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
[Display(ResourceType = typeof(Custom.Resource), Name="Account", Order=5, GroupName="Parameters")]
public string AccountName { get; set; }
public enum TextTemplates
{
// this part I don't know how to set
templateNameList.StringsToEnums<TemplateListEnum>( );
}
public static class StringEnumerableExtensions {
public static IEnumerable<T> StringsToEnums<T>( this IEnumerable<string> strs) where T : struct, IConvertible {
Type t = typeof( T );
var ret = new List<T>();
if( t.IsEnum ) {
T outStr;
foreach( var str in strs ) {
if( Enum.TryParse( str, out outStr ) ) {
ret.Add( outStr );
}
}
}
return ret;
}

Comment