I want to store additional information in my Enum
values and therefore came up with Attributes. Since I want a single property to carry 1..n strings
I tried to make the attribute constructor accept a variable parameter. Like this:
[AttributeUsage(AttributeTargets.Enum, AllowMultiple = false, Inherited = false)]
public class FileTypeAttribute : Attribute
{
public readonly string[] Extensions;
FileTypeAttribute(params string[] extensions)
{
this.Extensions = extensions;
}
}
My problem is that when I am now trying to make use of my property my compiler complains and leaves with the following error message which I really do not understand:
public enum EFileType
{
[FileTypeAttribute("txt")]
TEXTFILE,
[FileTypeAttribute("jpg", "png")]
PICTURE
}
Gives me:
'FileTypeAttribute' does not contain a constructor that takes '1' arguments
and
'FileTypeAttribute' does not contain a constructor that takes '2' arguments
Could anyone tell me please why this happens?
As far as I remember there is not really a possibility to make enums a little more "java'ish". But if I am missing any alternative I would be glad to hear about it.
The constructor is implicitly private
- explicitly mark it public
:
public FileTypeAttribute(params string[] extensions)
{
this.Extensions = extensions;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With