I want to make a generic method that gets a enum[]
and returns a string representing the comma-separated array items.
public static string ToSeparatedCommaString<T>(T[] enums)
where T : struct, IComparable, IFormattable, IConvertible//Não garante que seja enum mas sempre limita alguma coisa
{
var commaString = string.Empty;
foreach (var item in enums)
{
commaString += ((Enum)item).GetStringValue() + ",";
}
return commaString.TrimEnd(',');
}
The problem arises when I want to access the Extension Method GetStringValue()
.
Trying to cast cast , as you would expect, is not allowed.
Is there a way to achieve this?
GetStringValue()
is a method that returns a string whose value is indicated in the attribute associated with the element of enum