Konstruktor einer abgeleiteten Klasse deaktivieren/ausblendenC#

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

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);
}
}
Gibt es eine Möglichkeit, den Konstruktor für Implementierungen zu umgehen, die aus der Wirkung abgeleitet wurden, oder können Sie konstruktorfreie Implementierungen erhalten?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post