給構造器,我需要一個嵌套類傳遞到另一個ViewModel
誰擁有的構造是這樣的:通嵌套類使用反射
public CityEditViewModel(CityListViewModel.CityInfo info)
{
Model = Library.CityEdit.GetItem(info.Model.CityID);
}
從那裏我得到的數據是CityListViewModel
和它的類是嵌套CityInfo
。
詳細說明。 我有一個datagrid
其項目類型爲CityInfo
。那麼,當我從datagrid
中選擇該項目時,它應該打開新的ViewModel
誰是CitiyEditViewModel
(它應該將該類發送給我的構造函數上面)。
我曾嘗試以下操作:
Type EditClass = GetMyClass(subClass); //getting my CityEditViewModel
ConstructorInfo editConstructor = EditClass.GetConstructor(new Type[] { ChildClass }); // getting the constructor of that class
IScreen screen = (IScreen)(Activator.CreateInstance(EditClass, editConstructor)); //this part activates the window
//GetMyClass method
public Type GetMyClass(string type)
{
return Type.GetType(type);
}
但我得到的方法不存在例外。
EditClass.GetConstructors()返回什麼? –
什麼是「ChildClass」?它如何依賴於'CityListViewModel.CityInfo'? – HimBromBeere
你在哪裏傳遞構造函數參數? –