private static void BindTo(this IModelNodeDisabled modelNodeDisabled, object instance) { if (!modelNodeDisabled.NodeDisabled) { var modelNode = ((ModelNode)modelNodeDisabled); var modelNodeInfo = modelNode.NodeInfo; var propertyInfos = instance.GetType().Properties(); var propertiesHashSet = new HashSet <string>(propertyInfos.Select(info => info.Name)); var modelValueInfos = modelNodeInfo.ValuesInfo.Where(info => IsValidInfo(info, propertiesHashSet)).ToArray(); foreach (var valueInfo in modelValueInfos) { var propertyType = valueInfo.PropertyType == typeof(string) ? valueInfo.PropertyType : valueInfo.PropertyType.GetGenericArguments().First(); var value = modelNodeDisabled.GetValue(valueInfo.Name, propertyType); if (value != null) { instance.TrySetPropertyValue(valueInfo.Name, value); } } for (int i = 0; i < modelNodeDisabled.NodeCount; i++) { if (modelNodeDisabled.GetNode(i) is IModelNodeDisabled nodeEnabled) { var propertyValue = instance.GetPropertyValue(nodeEnabled.Id()); if (propertyValue != null) { (nodeEnabled).BindTo(propertyValue); } } } } }
public static IModelObjectView Get_ParentObjectView(IModelNodeDisabled modelNodeDisabled) { return(modelNodeDisabled.GetParent <IModelObjectView>()); }