private DataSchemaNode MakeSchemaElement(XmlSchemaElement element) { string typeName = (string)null; Type type = (Type)null; if (element.ElementSchemaType != null && element.ElementSchemaType.Datatype != null) { type = element.ElementSchemaType.Datatype.ValueType; } else if (element.SchemaTypeName != (XmlQualifiedName)null && element.SchemaTypeName.Name != string.Empty) { typeName = element.SchemaTypeName.Name; } if (type != (Type)null) { type = this.ConvertType(type); typeName = type.Name; } string str = this.ProcessQualifiedName(element.QualifiedName); SchemaNodeTypes nodeType = element.MaxOccurs > new Decimal(1) ? SchemaNodeTypes.Collection : SchemaNodeTypes.Property; DataSchemaNode schemaNode = new DataSchemaNode(str, str, nodeType, typeName, type, (IDataSchemaNodeDelayLoader)null); XmlSchemaComplexType schemaComplexType = element.ElementSchemaType as XmlSchemaComplexType; if (schemaComplexType != null) { XmlSchemaObjectCollection objectCollection = (XmlSchemaObjectCollection)null; if (schemaComplexType.Attributes.Count > 0) { objectCollection = schemaComplexType.Attributes; } else { XmlSchemaSimpleContent schemaSimpleContent = schemaComplexType.ContentModel as XmlSchemaSimpleContent; if (schemaSimpleContent != null) { XmlSchemaSimpleContentExtension contentExtension = schemaSimpleContent.Content as XmlSchemaSimpleContentExtension; if (contentExtension != null) { objectCollection = contentExtension.Attributes; } } } if (objectCollection != null) { foreach (XmlSchemaAttribute attribute in objectCollection) { DataSchemaNode child = this.MakeSchemaAttribute(attribute); schemaNode.AddChild(child); } } XmlSchemaGroupBase xmlSchemaGroupBase = schemaComplexType.Particle as XmlSchemaGroupBase; if (xmlSchemaGroupBase != null) { this.ProcessSchemaItems(schemaNode, xmlSchemaGroupBase.Items); } } return(schemaNode); }
private void AddMethodBasedChildren(DataSchemaNode node) { List <MethodInfo> supportedMethods = DataBindingDragDropAddTriggerHandler.GetSupportedMethods(this.DataSource.DocumentNode.TypeResolver, node.Type); if (supportedMethods == null || supportedMethods.Count == 0) { return; } for (int index = 0; index < supportedMethods.Count; ++index) { MethodInfo methodInfo = supportedMethods[index]; node.AddChild(new DataSchemaNode(methodInfo.Name, methodInfo.Name, SchemaNodeTypes.Method, (string)null, methodInfo.ReturnType, (IDataSchemaNodeDelayLoader)this) { IsReadOnly = true }); } }
private void ProcessSchemaItems(DataSchemaNode schemaNode, XmlSchemaObjectCollection items) { foreach (XmlSchemaObject xmlSchemaObject in items) { XmlSchemaElement element; if ((element = xmlSchemaObject as XmlSchemaElement) != null) { DataSchemaNode child = this.MakeSchemaElement(element); schemaNode.AddChild(child); } else { XmlSchemaChoice xmlSchemaChoice; if ((xmlSchemaChoice = xmlSchemaObject as XmlSchemaChoice) != null) { this.ProcessSchemaItems(schemaNode, xmlSchemaChoice.Items); } } } }
private void AddPropertyBasedChildren(DataSchemaNode node) { PropertyDescriptorCollection properties; try { properties = TypeDescriptor.GetProperties(node.Type); } catch { return; } foreach (PropertyDescriptor propertyDescriptor in properties) { Type propertyType; try { propertyType = propertyDescriptor.PropertyType; } catch { continue; } if (!propertyDescriptor.DesignTimeOnly) { SchemaNodeTypes nodeType = ClrObjectSchema.IsCollection(propertyType) ? SchemaNodeTypes.Collection : SchemaNodeTypes.Property; node.AddChild(new DataSchemaNode(propertyDescriptor.DisplayName, propertyDescriptor.Name, nodeType, propertyType.Name, propertyType, (IDataSchemaNodeDelayLoader)this) { IsReadOnly = propertyDescriptor.IsReadOnly }); } } PropertyInfo[] propertyInfoArray = (PropertyInfo[])null; try { propertyInfoArray = node.Type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy); } catch { } if (propertyInfoArray == null || propertyInfoArray.Length <= 0) { return; } for (int index = 0; index < propertyInfoArray.Length; ++index) { PropertyInfo propertyInfo = propertyInfoArray[index]; Type propertyType; try { propertyType = propertyInfo.PropertyType; } catch { continue; } if (propertyInfo.CanRead) { SchemaNodeTypes nodeType = ClrObjectSchema.IsCollection(propertyType) ? SchemaNodeTypes.Collection : SchemaNodeTypes.Property; node.AddChild(new DataSchemaNode(propertyInfo.Name, propertyInfo.Name, nodeType, propertyType.Name, propertyType, (IDataSchemaNodeDelayLoader)this) { IsReadOnly = !propertyInfo.CanWrite }); } } }