public T CreateInstance<T>() where T : class
{
var type = this._type;
var assembly = this._assembly;
#if !(XBOX || XBOX360)
// Check interfaces or Base type for casting purposes
if (type.GetInterface(typeof(T).Name, false) != null || type.BaseType.Name == typeof(T).Name)
#else
bool typeFound = false;
for (int i = 0; i < type.GetInterfaces().GetLength(0); i++)
{
if ( type.GetInterfaces()[ i ] == typeof( T ) )
{
typeFound = true;
break;
}
}
if ( typeFound )
#endif
{
try
{
return (T)Activator.CreateInstance(type);
}
catch (Exception e)
{
LogManager.Instance.Write("Failed to create instance of {0} of type {0} from assembly {1}", typeof(T).Name, type, assembly.FullName);
LogManager.Instance.Write(LogManager.BuildExceptionString(e));
}
}
return null;
}
}