mercredi 25 mars 2015

How to get all attributes and attributes data of a method using reflection in C#

The end goal is to copy the attributes "as is" from a method to another method in a generated class.



public class MyOriginalClass
{
[Attribute1]
[Attribute2("value of attribute 2")]
void MyMethod(){}
}

public class MyGeneratedClass
{
[Attribute1]
[Attribute2("value of attribute 2")]
void MyGeneratedMethod(){}
}


I am able to list the attribute of the method using MethodInfo.GetCustomAttributes() however, this does not give me the attributes arguments; which I need to generate the corresponding attribute on the generated class.


Note that I don't know the type of the attributes (can't cast the Attribute).


I am using CodeDom to generate code.






Aucun commentaire:

Enregistrer un commentaire