24 lines
		
	
	
		
			655 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			655 B
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using Engine.Core.Factory.Abstract;
 | 
						|
 | 
						|
namespace 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;
 | 
						|
    }
 | 
						|
}
 |