0

私はここのような属性の紹介を達成しようとしていますが、私の属性には次のようなプロパティ引数があります:[Foo(Bar = "Baz")]

引数を正しく渡すにはどうすればよいですか? 私は別のものから属性をコピーしていないので、CustomAttributeData を使用できないと思いますか?

4

1 に答える 1

1

You can set properties of your custom attributes by using ObjectConstruction.NamedArguments dictionary.

For example:

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);
}
于 2013-10-21T09:01:44.237 に答える