I need to decorate a large list of enums with a function to use, if it's this enum. I currently have this :
public enum AnimalType
{
[CustomSet(Helpers.ToUpper)]
Dog,
Snake,
Bird
}
public class CustomSet : Attribute
{
public Func<string, string> Function { get; set; }
public CustomSet(Func<string, string> function)
{
Function = function;
}
public string GetFix (string value)
{
return Function(value);
}
}
public static class Helpers
{
public static string ToUpper(string value)
{
return value.ToUpper();
}
}
However, the attribute on the enum gives me an error of
Error CS0181 Attribute constructor parameter 'function' has type 'Func<string, string>', which is not a valid attribute parameter type
Which I assume is due to the method not being a native type. Can anyone recommend a better way of doing this?
Thanks in advance
Func
s as values?