private void CollectProperties(object instance, EditorCommon.CustomPropertyDescriptor descriptor, List <Property> propertyCollection, bool noCategory, bool alphabetical, bool automaticlyExpandObjects, string filter, Property parentProperty, bool parentIsValueType, PropertyGrid hostGrid, bool mergeMultiValue, bool check = true) { if (descriptor.Attributes[typeof(FlatAttribute)] == null && check) { if (descriptor.IsBrowsable) { if (mergeMultiValue) { CollectPropertiesWithInstance(instance, descriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid); } else { var insType = instance.GetType(); var enumrableInterface = insType.GetInterface(typeof(IEnumerable).FullName, false); if (enumrableInterface != null) { foreach (var objIns in (IEnumerable)instance) { CollectPropertiesWithInstance(objIns, descriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid); } } else { CollectPropertiesWithInstance(instance, descriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid); } } } } else { instance = descriptor.GetValue(instance); if (instance == null) { return; } var insType = instance.GetType(); var enumrableInterface = insType.GetInterface(typeof(IEnumerable).FullName, false); if (enumrableInterface != null) { if (mergeMultiValue) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(instance); foreach (EditorCommon.CustomPropertyDescriptor propertyDescriptor in properties) { CollectProperties(instance, propertyDescriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, false); } } else { foreach (var objIns in (IEnumerable)instance) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(instance); foreach (EditorCommon.CustomPropertyDescriptor propertyDescriptor in properties) { CollectProperties(objIns, propertyDescriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, false); } } } } else { var properties = new EditorCommon.CustomPropertyDescriptorCollection(insType, TypeDescriptor.GetProperties(instance), parentIsValueType); foreach (EditorCommon.CustomPropertyDescriptor propertyDescriptor in properties) { CollectProperties(instance, propertyDescriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, false); } } } }
void CollectPropertiesWithInstance(object instance, EditorCommon.CustomPropertyDescriptor descriptor, List <Property> propertyCollection, bool noCategory, bool alphabetical, bool automaticlyExpandObjects, string filter, Property parentProperty, bool parentIsValueType, PropertyGrid hostGrid) { bool useCustomCtrl = false; bool showInnerProperties = false; var insType = instance.GetType(); var enumrableInterface = insType.GetInterface(typeof(IEnumerable).FullName, false); if (enumrableInterface != null) { foreach (var insObj in (IEnumerable)instance) { foreach (var att in descriptor.Attributes) { if (att is EngineNS.Editor.Editor_CustomEditorAttribute) { useCustomCtrl = true; } if (att is EngineNS.Editor.Editor_PropertyGridUIShowProviderAttribute) { if (descriptor.PropertyProvider == null) { var pgUIAtt = (EngineNS.Editor.Editor_PropertyGridUIShowProviderAttribute)att; var ins = System.Activator.CreateInstance(pgUIAtt.PropertyGridUIProviderType) as EngineNS.Editor.Editor_PropertyGridUIProvider; var proIns = descriptor.GetValue(insObj, false); descriptor.SetPropertyProvider(ins, proIns); } useCustomCtrl = descriptor.PropertyProvider.UseCustomCtrl; } else if (att is EngineNS.Editor.Editor_ShowOnlyInnerProperties) { showInnerProperties = true; useCustomCtrl = false; } else if (att is EngineNS.Editor.Editor_CustomEditorAttribute) { useCustomCtrl = true; } } break; } } else { foreach (var att in descriptor.Attributes) { if (att is EngineNS.Editor.Editor_PropertyGridUIShowProviderAttribute) { if (descriptor.PropertyProvider == null) { var pgUIAtt = (EngineNS.Editor.Editor_PropertyGridUIShowProviderAttribute)att; var ins = System.Activator.CreateInstance(pgUIAtt.PropertyGridUIProviderType) as EngineNS.Editor.Editor_PropertyGridUIProvider; var proIns = descriptor.GetValue(instance, false); descriptor.SetPropertyProvider(ins, proIns); } useCustomCtrl = descriptor.PropertyProvider.UseCustomCtrl; } else if (att is EngineNS.Editor.Editor_ShowOnlyInnerProperties) { showInnerProperties = true; useCustomCtrl = false; } else if (att is EngineNS.Editor.Editor_CustomEditorAttribute) { useCustomCtrl = true; } } } //Add a property with Name: AutomaticlyExpandObjects if (useCustomCtrl) { var property = new Property(instance, descriptor, parentProperty, hostGrid); propertyCollection.Add(property); } else if (showInnerProperties) { CollectProperties(instance, descriptor, propertyCollection, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, parentIsValueType, hostGrid, false, false); } else { Type propertyType = descriptor.GetPropertyType(instance); if (propertyType == typeof(EngineNS.GamePlay.Component.GPlacementComponent) || propertyType.IsSubclassOf(typeof(EngineNS.GamePlay.Component.GPlacementComponent))) { var property = new Property_HideName(instance, descriptor, parentProperty, hostGrid); propertyCollection.Add(property); } else if (propertyType.IsClass && !propertyType.IsArray && propertyType != typeof(string) && (propertyType.GetInterface(typeof(IEnumerable).FullName) == null)) { var property = new Property_Class(instance, descriptor, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, hostGrid); propertyCollection.Add(property); //if(automaticlyExpandObjects) // propertyCollection.Add(new ExpandableProperty(instance, descriptor, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, hostGrid)); //else //{ // var property = new Property(instance, descriptor, parentProperty, hostGrid); // propertyCollection.Add(property); //} } else if (propertyType.GetInterface(typeof(IEnumerable).FullName) != null && propertyType != typeof(string)) { // List等如果要用自定义属性框控件就要打上EngineNS.Editor.Editor_CustomEditorAttribute propertyCollection.Add(new ExpandableProperty(instance, descriptor, true, alphabetical, automaticlyExpandObjects, filter, parentProperty, hostGrid)); } else if (descriptor.Converter != null && descriptor.Converter.GetType() == typeof(ExpandableObjectConverter)) { propertyCollection.Add(new ExpandableProperty(instance, descriptor, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, hostGrid)); } else if (automaticlyExpandObjects && propertyType.IsValueType && !propertyType.IsPrimitive && propertyType != typeof(string) && !propertyType.IsEnum) { propertyCollection.Add(new ExpandableProperty(instance, descriptor, noCategory, alphabetical, automaticlyExpandObjects, filter, parentProperty, hostGrid)); } else { var property = new Property(instance, descriptor, parentProperty, hostGrid); propertyCollection.Add(property); } } }