Populate properties decorated with an attribute

Posted by PUT on Stack Overflow See other posts from Stack Overflow or by PUT
Published on 2010-03-25T11:09:18Z Indexed on 2010/03/25 11:13 UTC
Read the original article Hit count: 293

Filed under:
|
|
|

Are there any frameworks that assist me with this: (thinking that perhaps StructureMap can help me)

Whenever I create a new instance of "MyClass" or any other class that inherits from IMyInterface I want all properties decorated with [MyPropertyAttribute] to be populated with values from a database or some other data storage using the property Name in the attribute.

public class MyClass : IMyInterface
{
    [MyPropertyAttribute("foo")]
    public string Foo { get; set; }
}

[AttributeUsage(AttributeTargets.Property)]
public sealed class MyPropertyAttribute : System.Attribute
{
    public string Name
    {
        get;
        private set;
    }

    public MyPropertyAttribute(string name)
    {
        Name = name;
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about structuremap