Friday, April 24, 2015

DRY principles - Finding entities via Attributes.

With the new contracting gig I'm in right now...

var types = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
    from type in assembly.GetTypes()
    where Attribute.IsDefined(type, typeof(FCBids.Domain.AuditEntityAttribute), false) && !type.Namespace.Equals("System.Data.Entity.DynamicProxies")
    select type).ToList();

foreach (var type in types)
{
    /// do what you need to here.
    /// ....
}

No comments: