Exemple #1
0
        public static SchemaInfo CreateFrom(IEnumerable <XmlIntellisenseInfo> intellisenseInfos)
        {
            var schemaInfo = new SchemaInfo
            {
                Tags = new List <TagInfo>()
            };

            foreach (var pair in intellisenseInfos)
            {
                var name = pair.TagName;
                var type = pair.Type;

                ForceToLoadDependencyProperties(type);

                var tag = new TagInfo
                {
                    Name       = name,
                    Attributes = new List <AttributeInfo>()
                };
                var dependencyProperties = DependencyProperty.GetAllProperties(type);
                foreach (var dp in dependencyProperties)
                {
                    var attributeInfo = new AttributeInfo {
                        Name = dp.Name
                    };
                    if (dp.PropertyType == typeof(bool))
                    {
                        attributeInfo.Values = new[] { "true", "false" };
                    }

                    if (dp.PropertyType.IsEnum)
                    {
                        attributeInfo.Values = Enum.GetNames(dp.PropertyType);
                    }

                    tag.Attributes.Add(attributeInfo);
                }
                if (pair.ChildrenTags != null)
                {
                    tag.ChildrenTags = pair.ChildrenTags;
                }
                schemaInfo.Tags.Add(tag);
            }

            return(schemaInfo);
        }