22 lines
		
	
	
		
			610 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			610 B
		
	
	
	
		
			C#
		
	
	
	
	
	
using Engine.Core.Exceptions;
 | 
						|
 | 
						|
namespace Engine.Core.Factory;
 | 
						|
 | 
						|
public class StateEnableFactory
 | 
						|
{
 | 
						|
    public static IStateEnable Instantiate(IEntity entity) => Instantiate<StateEnable>(entity);
 | 
						|
 | 
						|
    public static T Instantiate<T>(IEntity entity, params object?[]? args) where T : class, IStateEnable
 | 
						|
    {
 | 
						|
        T stateEnable = TypeFactory.Get<T>(args);
 | 
						|
 | 
						|
        if (!entity.Assign(stateEnable))
 | 
						|
            throw AssignFailedException.From(entity, stateEnable);
 | 
						|
 | 
						|
        if (!stateEnable.Assign(entity))
 | 
						|
            throw AssignFailedException.From(stateEnable, entity);
 | 
						|
 | 
						|
        return stateEnable;
 | 
						|
    }
 | 
						|
}
 |