How i get an object instance's annotation or Custom Attribute?

Is it possible to access the Object instance's Annotation definition?

Lets Say I have the following Code:

public class A
{
    [CustomStuff( Value="" )]
    public B propertyB;
}

In another class i receive an instance of B as parameter, is it possible to get the annotations from that object?

Upvotes: 0

Views: 361

Answers (1)

Rob
Rob

Reputation: 27367

Not possible, and it doesn't really make sense to be able to do it. Annotations are on properties, not instances. Take for example:

public class A
{
    [CustomStuff( Value="Something" )]
    public B One;

    [CustomStuff( Value="SomethingElse" )]
    public B Two;

    [MoreCustom( Value="" )]
    public B One;
}

And then using it:

var a = new A();
DoSomething(a.One);

public void DoSomething(B instance) 
{
    //What should the result be here?
    //Should be 'CustomStuff:Something', right?    
}

var a = new A();
a.Two = a.One
DoSomething(a.One);

//Now what should it be?

var a = new A();
a.Two = a.One
var tmp = a.One;
a.One = a.Two = null;
DoSomething(tmp);

//And now?

Upvotes: 1

Related Questions