Setting an attribute property to the type of the decorated class.

Posted by cmaduro on Stack Overflow See other posts from Stack Overflow or by cmaduro
Published on 2010-05-20T23:18:23Z Indexed on 2010/05/21 0:00 UTC
Read the original article Hit count: 112

Filed under:
|

Is it possible to get the decorated class' type inside of the custom attribute's class? For example:

[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false)]
public class ViewAttribute : ExportAttribute
{

    public object TargetRegion { get; set; }
    public Type ViewModel { get; set; }
    public Type Module { get; set; }

    public ViewAttribute()
        : base(typeof(UserControl))
    {
        Module = GetDecoratedClassType(); //I need this method
    }
}

In the following example GetDecoratedClassType() would return HomeView

[View]
HomeView MyHomeView { get; set; }

© Stack Overflow or respective owner

Related posts about custom-attributes

Related posts about c#