예제 #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());
 }
예제 #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");
        }
예제 #3
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
                    });
                }
            }
        }