22 lines
540 B
C#
22 lines
540 B
C#
using System;
|
|
|
|
namespace Syntriax.Engine.Core.Factory;
|
|
|
|
public static class TypeFactory
|
|
{
|
|
public static T Get<T>(params object?[]? args) where T : class
|
|
{
|
|
T? result;
|
|
|
|
if (args is not null && args.Length != 0)
|
|
result = Activator.CreateInstance(typeof(T), args) as T;
|
|
else
|
|
result = Activator.CreateInstance(typeof(T)) as T;
|
|
|
|
if (result is null)
|
|
throw new Exception($"{typeof(T).Name} of type {typeof(T).Name} could not be created.");
|
|
|
|
return result;
|
|
}
|
|
}
|