Exemplo n.º 1
0
 void IDataSchemaNodeDelayLoader.ProcessChildren(DataSchemaNode node)
 {
     if ((node.NodeType | SchemaNodeTypes.Method) == SchemaNodeTypes.Method)
     {
         return;
     }
     if (ClrObjectSchema.IsCollection(node.Type))
     {
         Type type = CollectionAdapterDescription.GetGenericCollectionType(node.Type);
         if (type == (Type)null)
         {
             type = typeof(object);
         }
         SchemaNodeTypes nodeType = SchemaNodeTypes.CollectionItem;
         if (ClrObjectSchema.IsCollection(type))
         {
             nodeType |= SchemaNodeTypes.CollectionItem;
         }
         DataSchemaNode dataSchemaNode = new DataSchemaNode(node.PathName, DataSchemaNode.IndexNodePath, nodeType, string.Empty, type, (IDataSchemaNodeDelayLoader)this);
         node.CollectionItem = dataSchemaNode;
     }
     else
     {
         this.AddMethodBasedChildren(node);
     }
     this.AddPropertyBasedChildren(node);
     node.Children.Sort((IComparer <DataSchemaNode>) new DataSchemaNode.PathNameComparer());
 }
Exemplo n.º 2
0
        public ClrObjectSchema(Type type, DocumentNode dataSourceNode)
        {
            SchemaNodeTypes nodeType = ClrObjectSchema.IsCollection(type) ? SchemaNodeTypes.Collection : SchemaNodeTypes.Property;

            this.root       = new DataSchemaNode(type.Name, type.Name, nodeType, (string)null, type, (IDataSchemaNodeDelayLoader)this);
            this.dataSource = (DataSourceNode) new ClrObjectDataSourceNode(this, dataSourceNode);
            this.OnPropertyChanged("Root");
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public DataSchemaNode(string displayName, string pathName, SchemaNodeTypes nodeType, string typeName, Type type, IDataSchemaNodeDelayLoader loader)
 {
     this.pathName       = pathName;
     this.NodeType       = nodeType;
     this.type           = type;
     this.loader         = loader;
     this.rawDisplayName = displayName;
     this.typeName       = typeName;
 }
Exemplo n.º 5
0
        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
                    });
                }
            }
        }