I have bunch of classes and a custom attribute class. All my classes have unique id which defined in my attribute. I add instance of my classes in a list randomly. How can I identify which class by just checking attribute.
Basicly,
I have an attribute class
public class myAtt : Attribute
{
public int id;
public myAtt(int id){ this.id = id; }
}
I have an enum
public enum myEnum
{
IT_IS_A_CLASS,
IT_IS_B_CLASS,
IT_IS_C_CLASS
}
Bunch of classes that have this attribute
[myAtt((int)myEnum.IT_IS_A_CLASS)]
public class A
{
}
[myAtt((int)myEnum.IT_IS_B_CLASS)]
public class B
{
}
[myAtt((int)myEnum.IT_IS_C_CLASS)]
public class C
{
}
I have a thread function that dequeue item from queue that filled by another thread. Do not mind thread-safety.
while(true)
{
var temp = myQ.Dequeue();
switch((myEnum)temp.id) <-- I basicly want to this entire switch become one-liner.
{
case myEnum.IT_IS_A_CLASS: aFunction(new A()); break;
case myEnum.IT_IS_B_CLASS: aFunction(new B()); break;
case myEnum.IT_IS_C_CLASS: aFunction(new C()); break;
.
.
.
case myEnum.IT_IS_Z_CLASS: aFunction(new Z()); break;
}
}
I basicly want to remove this entire switch and become one-liner. Like
while(true)
{
var temp = myQ.Dequeue();
aFunction(magicFunction((myEnum)temp.id));
}