P
Paul E Collins
Hello.
I want an enum where each member corresponds to a method call - which
seems reasonable enough.
I tried something along these lines:
internal class MyAttribute : Attribute
{
public delegate void MyDelegate(int i);
MyDelegate m_d = null;
public MyAttribute(MyDelegate d) { m_d = d; }
}
// ... in another class ...
public enum Something
{
[MyAttribute(new MyAttribute.MyDelegate(SomeMethod))] Blah
}
private static void SomeMethod(int i) { }
However, I'm not allowed to create that MyDelegate within the enum,
because "an attribute argument must be a constant expression, typeof
expression or array creation expression".
What would you folks suggest as a workaround?
P.
I want an enum where each member corresponds to a method call - which
seems reasonable enough.
I tried something along these lines:
internal class MyAttribute : Attribute
{
public delegate void MyDelegate(int i);
MyDelegate m_d = null;
public MyAttribute(MyDelegate d) { m_d = d; }
}
// ... in another class ...
public enum Something
{
[MyAttribute(new MyAttribute.MyDelegate(SomeMethod))] Blah
}
private static void SomeMethod(int i) { }
However, I'm not allowed to create that MyDelegate within the enum,
because "an attribute argument must be a constant expression, typeof
expression or array creation expression".
What would you folks suggest as a workaround?
P.