Thursday, April 9, 2009

How to load dll dynamically at runtime & create instances.

public static T GetInstanceByCustomAttribute(Assembly assembly, string customAttributeName)
{
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{

Object[] attributes = (Object[])type.GetCustomAttributes(false);


foreach (Object attribute in attributes)
{
//"LoggingFactoryImplementaionAttribute";

if (attribute.GetType().Name.ToLower().Equals(customAttributeName.ToLower()))
{
return (T)Activator.CreateInstance(type);

}
}
}
return default(T);
}

No comments:

Post a Comment