给构造器,我需要一个嵌套类传递到另一个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
你在哪里传递构造函数参数? –