I have a problem I have a simple enum with description attribute in c#
public enum Service
{
[Description("Unknown")]
Unknown = 0
}
No I have extension in f# that will get me that description and it looks like:
[<Extension>]
static member inline GetEnumDescription(enum:'TEnum when 'TEnum :> Enum) : string =
try
let attributes : seq<DescriptionAttribute[]> = enum.GetType().GetField(enum.ToString()).GetCustomAttributes(typedefof<DescriptionAttribute>, false) |> Seq.cast<DescriptionAttribute[]>
match attributes |> Seq.length > 0 with
| true ->
let attribute : DescriptionAttribute = enum |> Seq.head
attribute.Description
| _ -> enum.ToString()
with
| :? EnumException as ex ->
EnumExtensions._logger.Error(sprintf "Exception in getting enum description - %s" ex.Message)
enum.ToString()
So meta in c# looks like:
[CompilationMapping(SourceConstructFlags.ObjectType)]
public class EnumExtensions
{
public EnumExtensions();
public static string GetEnumDescription<TEnum>(this TEnum @enum) where TEnum : Enum, IEnumerable<DescriptionAttribute>;
}
Now when i try using this in c# calling :
public string Description => Service.GetEnumDescription(); //Service is set to Unknown enum value
I am getting something like:
Error CS0315 The type 'Enums.Service' cannot be used as type parameter 'TEnum' in the generic type or method 'EnumExtensions.GetEnumDescription(TEnum)'. There is no boxing conversion from 'Enums.Service' to 'System.Collections.Generic.IEnumerable'.
I am lost at this.