protected ChoiceActionItem CreateItem(Type type, IModelBaseChoiceActionItem info) { if (info == null) { var choiceActionItem = new ChoiceActionItem(type.Name, type); IModelClass modelClass = Application.Model.BOModel.GetClass(type); if (modelClass != null) { choiceActionItem.Caption = modelClass.Caption; choiceActionItem.ImageName = modelClass.ImageName; } return(choiceActionItem); } return(new ChoiceActionItem(info, type)); }
private IModelBaseChoiceActionItem CreateModelBase(IModelBaseChoiceActionItem source) { if (source == null) { return(null); } var type = source.GetType(); var nodeInfo = ModelEditorHelper.CreateDummyNodeInfo(); var result = Activator.CreateInstance(type, nodeInfo, "@" + Guid.NewGuid().ToString()); var viewProperty = type.GetProperty("View"); var sourceView = viewProperty?.GetMethod?.Invoke(source, new object[] { }); //foreach (var propertyInfo in type.GetProperties()) //{ // var genericListType = GetGenericListType(propertyInfo.PropertyType); // if (genericListType != null) // { // var instanceType = genericListType.GetGenericArguments()[0]; // var sourceList = (IEnumerable)propertyInfo.GetGetMethod()?.Invoke(source, null); // if (sourceList == null) // { // continue; // } // var addMethod = propertyInfo.PropertyType.GetMethods() // .FirstOrDefault( // m => // { // if (m.Name == "Add") // { // var parameterInfos = m.GetParameters(); // return parameterInfos.Length == 1 // && parameterInfos[0].ParameterType == instanceType; // } // return false; // }); // foreach (var s in sourceList) // { // //var changeType = Convert.ChangeType(s, instanceType); // var clone = s.Clone(ChoiceActionItemCloneFunction); // addMethod?.Invoke( // propertyInfo.GetMethod?.Invoke(result, null), // new object[] { clone }); // } // } // else // { // object sourcePropertyValue = null; // switch (propertyInfo.Name) // { // case "Id": // sourcePropertyValue = "@" + Guid.NewGuid(); // break; // case "Item": // break; // case "Root": // sourcePropertyValue = source.Root; // break; // default: // sourcePropertyValue = (propertyInfo.GetGetMethod()?.Invoke(source, null)).Clone(ChoiceActionItemCloneFunction); // break; // } // propertyInfo.GetSetMethod()?.Invoke(result, new object[] { sourcePropertyValue }); // } //} return((IModelBaseChoiceActionItem)result); }