/// <summary>
/// Retrieve the generic element type from the templated type.
/// </summary>
static public Type GetGenericArgument (this Type type)
{
Type[] elems = type.GetGenericArguments();
return (elems != null && elems.Length == 1) ? elems[0] : null;
}
/// <summary>
/// Create a new instance of the specified object.
/// </summary>
static public object Create (this Type type)
{
try
{
return Activator.CreateInstance(type);
}
catch (Exception ex)
{
Debug.LogError(ex.Message);
return null;
}
}
/// <summary>
/// Create a new instance of the specified object.
/// </summary>
static public object Create (this Type type, int size)
{
try
{
return Activator.CreateInstance(type, size);
}
catch (Exception)
{
return type.Create();
}
}