最终目标是将一个方法中的属性“原封不动”地复制到生成类中的另一个方法中。
public class MyOriginalClass
{
[Attribute1]
[Attribute2("value of attribute 2")]
void MyMethod(){}
}
public class MyGeneratedClass
{
[Attribute1]
[Attribute2("value of attribute 2")]
void MyGeneratedMethod(){}
}
我可以使用MethodInfo.GetCustomAttributes()
列出方法的属性,但这不会给我属性参数;而我需要生成相应的属性以在生成的类上使用。
请注意,我不知道属性的类型(无法强制转换Attribute)。
我正在使用CodeDom生成代码。