0
我想實現的屬性引入像here屬性,但是我的屬性有屬性的參數,如:[Foo(Bar = "Baz")]
Postsharp推出帶有屬性參數
如何正確地傳遞參數?我沒有複製別的屬性,所以我不認爲我可以使用CustomAttributeData?
我想實現的屬性引入像here屬性,但是我的屬性有屬性的參數,如:[Foo(Bar = "Baz")]
Postsharp推出帶有屬性參數
如何正確地傳遞參數?我沒有複製別的屬性,所以我不認爲我可以使用CustomAttributeData?
您可以使用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);
}