chore: Added Initial Engine Code
This commit is contained in:
23
Engine.Core/Factory/FactoryBase.cs
Normal file
23
Engine.Core/Factory/FactoryBase.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user