void btn_Click(object sender, RoutedEventArgs e) { ButtonExt b = sender as ButtonExt; object t = b.ObjectToModyfy as object; CollectionEditor ed = new CollectionEditor(t, b.PropertyName); ed.ShowDialog(); if (ed.ShouldSave == true) { PropertyInfo pi = lbxObjects.SelectedItem.GetType().GetProperty(ed.editingPropertyName); //int itemCount = (int)obj.GetType().GetProperty("Count").GetValue(obj, null); Type type = lbxObjects.SelectedItem.GetType(); PropertyInfo pif = lbxObjects.SelectedItem.GetType().GetProperty(ed.editingPropertyName); MethodInfo clearMethod = pif.GetValue(lbxObjects.SelectedItem, null).GetType().GetMethod("Clear"); MethodInfo addMethod = pif.GetValue(lbxObjects.SelectedItem, null).GetType().GetMethod("Add"); clearMethod.Invoke(lbxObjects.SelectedItem.GetType().GetProperty(ed.editingPropertyName).GetValue(lbxObjects.SelectedItem, null), null); //object clearvalue = propertyType.Invoke(lbxObjects.SelectedItem, null); foreach (var v in ed.ObjectList) { object[] param = new object[1]; param[0] = v; addMethod.Invoke(lbxObjects.SelectedItem.GetType().GetProperty(ed.editingPropertyName).GetValue(lbxObjects.SelectedItem, null), param); } } }
void btn_Click(object sender, RoutedEventArgs e) { ButtonExt b = sender as ButtonExt; object t = b.Tag as object; CollectionEditor ed = new CollectionEditor(t, b.PropertyName); ed.ShowDialog(); }