返回继承了某个类的新类

时间:2019-05-23 15:31:03

标签: c# unity3d inheritance

我正在进行自定义的CharacterStatusfunctionManagement。 有CharacterStatusFunction和继承的类,如 力量,保卫,燃烧和其他。

public class CharacterStatusFunction : IComparable<CharacterStatusFunction> {
      //Something
 }

 public class Strength : CharacterStatusFunction {
 }

我在CharacterStatusfunctionManage中加载所有继承的类

static Dictionary<string, CharacterStatusFunction> _CharacterStatusFuncDic = new Dictionary<string, CharacterStatusFunction> ();
 static List<string> _CharacterStatusFuncKeyLists = new List<string> ();

[RuntimeInitializeOnLoadMethod]
 public static void InItDictionary () {
  List<CharacterStatusFunction> ChrStatusFunctionLists = ReflectiveEnumerator.GetEnumerableOfType<CharacterStatusFunction> ().ToList ();
  for (int i = 0; i < ChrStatusFunctionLists.Count; i++) {
     _CharacterStatusFuncDic.Add (ChrStatusFunctionLists[i].ToString (), ChrStatusFunctionLists[i]);
  }
  Added = true;
  }

我想像这样通过我的objectlug获得New CharacterStatusManagement。

public static CharacterStatusFunction GetCharacterStatusFunctionByKey (string key) {
 if(key == "Strength")
 return new Strength{}
 //something else
 }

这是一个问题:我想获得继承了characterstatusfunction类的'new'类,但是我找不到办法。 我知道有一种使用序列化进行深度复制的方法,但是因为我没有复制值,所以我认为这不合适。

 public static CharacterStatusFunction GetCharacterStatusFunctionByKey (string key) {
  if (_CharacterStatusFuncDic.ContainsKey (key)) {
     //This Line Help 
     return new typeof(_CharacterStatusFuncDic[key]);
    } 
}

0 个答案:

没有答案