我试图实现属性介绍,比如这里,但是我的属性有属性参数,比如:[Foo(Bar = "Baz")]
如何正确传递参数?我不会从其他地方复制属性,所以我认为我不能使用CustomAttributeData?
发布于 2013-10-21 09:01:44
可以使用ObjectConstruction.NamedArguments字典设置自定义属性的属性。
例如:
public IEnumerable<AspectInstance> ProvideAspects(object targetElement)
{
Type targetType = (Type) targetElement;
var objectConstruction =
new ObjectConstruction(typeof (MyCustomAttribute).GetConstructor(Type.EmptyTypes));
objectConstruction.NamedArguments["Bar"] = "Baz";
var introduceAttributeAspect = new CustomAttributeIntroductionAspect(objectConstruction);
yield return new AspectInstance(targetType, introduceAttributeAspect);
}https://stackoverflow.com/questions/19477654
复制相似问题