Konstruktor einer abgeleiteten Klasse deaktivieren/ausblenden [geschlossen]C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Konstruktor einer abgeleiteten Klasse deaktivieren/ausblenden [geschlossen]

Post by Anonymous »

Also habe ich eine Art Domänen-API erstellt, um Verhaltensklassen zu schreiben, und bin an den Punkt gekommen, an dem ich das folgende Implementierungsformat habe: < /p>

Code: Select all

[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>
Gibt es eine Möglichkeit, den Konstruktor für Implementierungen zu umgehen, die aus der Wirkung abgeleitet werden, oder können Sie konstruktorfreie Implementierungen erhalten, um es in das folgende Format zu ermöglichen: < /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);
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post