Reputation: 33
I know you can give them methods by creating an extension method on another class, but are properties possible as well? The best you can do as far as I know is using an extension method that takes zero parameters.
In case you're wondering why I ask this, I have this enum with some custom attributes:
enum Operator : byte
{
[Category(OperatorCategory.Multiplicative), Symbol("") ] None,
[Category(OperatorCategory.Additive), Symbol("+") ] Add,
[Category(OperatorCategory.Additive), Symbol("\u2212")] Subtract,
[Category(OperatorCategory.Multiplicative), Symbol("\u22C5")] Multiply,
[Category(OperatorCategory.Multiplicative), Symbol("\u00F7")] Divide,
[Category(OperatorCategory.Exponential), Symbol("^") ] Exponent,
[Category(OperatorCategory.Exponential), Symbol("\u221A")] Root,
[Category(OperatorCategory.Exponential), Symbol("log") ] Logarithm
}
I want to do a really simple thing: add a .Category
property that returns the category of the operator (so I don't have to type the same thing all over again).
Upvotes: 0
Views: 1329
Reputation:
Take a look at this article, it might give you some insight into what you want:
Using Enumeration Classes instead of Enum Types
I have not tried this, I just thought it looked relevant. My suggestion was going to be create a class that holds a list of your properties, then the integer based index of the enum, instead of a byte that you used, could be used to retrieve the property value you need based on the enum value.
Upvotes: 1