我试图通过同名的字符串传递类型和对泛型的引用:
IE: string ButtonName == "ActionOne" ~~~~~>> Type == ActionOne, reference == ActionOne
可悲的是,我不知道正确的语法是什么,并且很难通过谷歌找到它,所以如果有人知道如何做到这一点,或者至少知道它叫什么,那将有很大帮助!
谢谢,这是我正在尝试做的一些 sudo 代码!
public class ActionPanelButton : *NotImportant* {
private string ButtonName;
private Type ButtonType;
void ActionPanelButton(){
ButtonName = this.Button.name; // This is return a string set by the user
ButtonType = Type.GetType(ButtonName);
ActionPanel = this.Button.parent.ActionPanel; // This will return the containing panel object
}
public void LeftClick(){ //This responds like any-ol OnClick
ActionPanel.ChangeSelectedActionBundle<(ButtonType)>(ActionPanel.DisplayedActionPanel.(ButtonType));
}
}
公共类 ActionPanel....
public void ChangeSelectedActionBundle <T> (T action){
Type typeOfObject = typeof(ActionBundle);
Type typeOfAction = typeof(T);
FieldInfo field = typeOfObject.GetField(typeOfAction.Name);
field.SetValue(SelectionManager.SelectedActionBundle, action);
}