Example #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());
 }
Example #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");
        }
Example #3
0
        private static IType GetTypeFromDataSource(RawDataSourceInfoBase dataSource)
        {
            if (!dataSource.IsValid || dataSource.SourceNode == null)
            {
                return((IType)null);
            }
            IType type = DataContextHelper.GetDataType(dataSource.SourceNode);

            if (dataSource.HasClrPath && type != null && type.RuntimeType != (Type)null)
            {
                DataSchemaNodePath nodePathFromPath = new ClrObjectSchema(type.RuntimeType, dataSource.SourceNode).GetNodePathFromPath(dataSource.ClrPath);
                type = nodePathFromPath != null ? nodePathFromPath.Type : (IType)null;
            }
            return(type);
        }
Example #4
0
        public ISchema MakeRelativeToNode(DataSchemaNode node)
        {
            ClrObjectSchema clrObjectSchema;

            if (node == this.Root)
            {
                clrObjectSchema = this;
            }
            else if (node != null)
            {
                clrObjectSchema = new ClrObjectSchema(node, this.DataSource.DocumentNode);
            }
            else
            {
                DataSchemaNode absoluteRoot = this.AbsoluteRoot;
                clrObjectSchema = this.Root != absoluteRoot ? new ClrObjectSchema(absoluteRoot, this.DataSource.DocumentNode) : this;
            }
            return((ISchema)clrObjectSchema);
        }
        private string GetPropertyPathExtension(DocumentCompositeNode documentNode, IProperty targetProperty, DataContextPropertyPathExtension pathExtension)
        {
            if (!pathExtension.IsValid)
            {
                return((string)null);
            }
            DocumentNode node = documentNode.Properties[(IPropertyId)targetProperty];

            if (node == null || !PlatformTypes.String.IsAssignableFrom((ITypeId)node.Type))
            {
                return(string.Empty);
            }
            string localPath = DocumentPrimitiveNode.GetValueAsString(node);

            if (pathExtension.IsCollectionItem)
            {
                localPath = ClrObjectSchema.CombinePaths(DataSchemaNode.IndexNodePath, localPath);
            }
            return(localPath);
        }
Example #6
0
        private static string ProvideNodePathForPendingEdit(DataSchemaItem parentItem, string newPropertyName, params SampleProperty[] renamedProperties)
        {
            DataSchemaNodePath dataSchemaNodePath = parentItem.DataSchemaNodePath;
            DataSchemaNode     endNode            = (DataSchemaNode)null;

            if (dataSchemaNodePath.IsCollection)
            {
                endNode = dataSchemaNodePath.EffectiveCollectionItemNode;
            }
            if (endNode == null)
            {
                endNode = dataSchemaNodePath.Node;
            }
            if (endNode == null)
            {
                return(newPropertyName);
            }
            string inheritedPath = (string)null;

            if (renamedProperties.Length == 0)
            {
                if (endNode != dataSchemaNodePath.Node)
                {
                    dataSchemaNodePath = new DataSchemaNodePath(dataSchemaNodePath.Schema, endNode);
                }
                return(ClrObjectSchema.CombinePaths(dataSchemaNodePath.Path, newPropertyName));
            }
            List <string> list = new List <string>()
            {
                newPropertyName
            };
            string pathName = endNode.PathName;

            for (DataSchemaNode parent = endNode.Parent; parent != null; parent = parent.Parent)
            {
                SampleCompositeType sampleCompositeType = parent.SampleType as SampleCompositeType;
                if (sampleCompositeType == null)
                {
                    list.Add(pathName);
                }
                else
                {
                    string         name           = pathName;
                    SampleProperty sampleProperty = sampleCompositeType.GetSampleProperty(name);
                    if (Enumerable.FirstOrDefault <SampleProperty>((IEnumerable <SampleProperty>)renamedProperties, (Func <SampleProperty, bool>)(p => p == sampleProperty)) != null)
                    {
                        name = newPropertyName;
                    }
                    list.Add(name);
                }
                if (parent != dataSchemaNodePath.Schema.Root)
                {
                    pathName = parent.PathName;
                }
                else
                {
                    break;
                }
            }
            for (int index = list.Count - 1; index >= 0; --index)
            {
                inheritedPath = ClrObjectSchema.CombinePaths(inheritedPath, list[index]);
            }
            return(inheritedPath);
        }
Example #7
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
                    });
                }
            }
        }
Example #8
0
 public ClrObjectDataSourceNode(ClrObjectSchema schema, DocumentNode entryNode)
     : base(entryNode)
 {
     this.schema     = (ISchema)schema;
     this.sourceType = schema.Root.Type;
 }