24 lines
673 B
C#
24 lines
673 B
C#
using System;
|
|
using Syntriax.Engine.Core.Factory.Abstract;
|
|
|
|
namespace Syntriax.Engine.Core.Factory;
|
|
|
|
public abstract class FactoryBase<TInterface> : IFactory<TInterface>
|
|
where TInterface : class
|
|
{
|
|
public virtual T Get<T>(params object?[]? args) where T : class, TInterface
|
|
{
|
|
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(TInterface).Name} of type {typeof(T).Name} could not be created.");
|
|
|
|
return result;
|
|
}
|
|
}
|