Friday, April 17, 2009 5:24 PM
/// <summary>
/// using reflection to create an instance of a generic type
/// </summary>
/// <returns>T as the generic type</returns>
private static T GetNewObject()
{
try
{
return (T)typeof(T).GetConstructor(new Type[] { }).Invoke(new object[] { });
}
catch {
return default(T);
}
}
/// <summary>
/// Create an instance of type T using the activator
/// </summary>
/// <returns></returns>
private static T GetNewInstance()
{
return (T)Activator.CreateInstance<T>();
}