Итак, я делал какой-то API домена для написания классов поведения, и дошел до того, что у меня есть следующий формат реализации: < /p>
[ImplementationName(EffectName)]
public class TestImplementation : Effect, IUniqueEffect
{
public TestImplementation(EffectContext context) : base(context) { }
public override void OnCreate() => UnityEngine.Debug.Log("Test message");
float IUniqueEffect.GetAttrubuteBonus(SomeData data) => EffectOwner.BaseAttributeValue - 1f;
}
public class Effect
{
public Effect(EffectContext context)
{
EffectOwner = context.EffectOwner;
}
//Unit here is a facade for set of entities
public Unit EffectOwner { get; }
}
public class EffectFactory
{
private readonly IConstructorRepository _constructorRepository;
private readonly object[] _args;
private int _nextId;
public Effect Create(EffectName name, UnitId target)
{
if (_constructorRepository.TryGet(name, out ConstructorInfo constructorInfo) == false)
{
return null;
}
int effectId = _nextId++;
EffectContext context = new(effectId, name, _unitRepository.Get(parentId));
_args[0] = context;
return (Effect) constructorInfo.Invoke(_args);
}
}
< /code>
Есть ли способ обойти добавление конструктора для реализаций, полученных из эффекта, или любого способа получить реализации без конструкторов, чтобы превратить его в следующее формат: < /p>
[ImplementationName(EffectName)]
public class TestImplementation : Effect, IUniqueEffect, IUniqueEffect2
{
public override void OnCreate() => UnityEngine.Debug.Log("Test message");
//EffectOwner is Unit stored in Effect
float IUniqueEffect.GetAttrubuteBonus(SomeData data) => EffectOwner.BaseAttributeValue - 1f;
void IUniqueEffect2.HandleEvent(SomeData2 data) => ExtendDuration(5f);
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... ived-class