示例#1
0
        private static ApiProperty CreateApiPropertyFromDomAttribute(DomAttribute domAttribute)
        {
            Contract.Requires(domAttribute != null);

            var apiPropertyName        = domAttribute.ApiPropertyName;
            var domAttributeCollection = domAttribute.Nodes()
                                         .Cast <DomAttribute>()
                                         .ToList();
            var apiObject   = CreateApiObjectFromDomAttributeCollection(domAttributeCollection);
            var apiProperty = ApiProperty.Create(apiPropertyName, apiObject);

            return(apiProperty);
        }
示例#2
0
        // PRIVATE METHODS //////////////////////////////////////////////////
        #region Methods
        private static DomAttribute CreateFromClrAttribute(IAttributeInfo attributeInfo, object clrAttribute)
        {
            Contract.Requires(attributeInfo != null);

            var apiPropertyName = attributeInfo.ApiPropertyName;
            var clrPropertyName = attributeInfo.ClrPropertyName;
            var clrPropertyType = attributeInfo.ClrPropertyType;

            var apiAttribute = ApiProperty.Create(apiPropertyName, clrPropertyType, clrAttribute);

            var domAttribute = new DomAttribute(apiAttribute, apiPropertyName, clrAttribute, clrPropertyName, clrPropertyType);

            return(domAttribute);
        }
示例#3
0
        private static ApiObject CreateApiObjectFromDomAttributeCollection(IEnumerable <DomAttribute> domAttributeCollection)
        {
            Contract.Requires(domAttributeCollection != null);

            var apiProperties = domAttributeCollection
                                .Select(domAttribute =>
            {
                if (!domAttribute.HasNodes())
                {
                    // Simple attribute, has no children.
                    return(domAttribute.ApiAttribute);
                }

                // Complex attribute or collection of Complex attribute
                var isCollection = domAttribute.FirstNode.NodeType == DomNodeType.Index;
                if (isCollection)
                {
                    // Collection of Complex attributes, has children of DomIndex.
                    var domIndexCollection = domAttribute.Nodes()
                                             .Cast <DomIndex>()
                                             .ToList();

                    var apiObjectArray = domIndexCollection.Select(CreateApiObjectFromDomIndex)
                                         .ToArray();

                    var apiPropertyName = domAttribute.ApiPropertyName;
                    var apiProperty     = ApiProperty.Create(apiPropertyName, apiObjectArray);
                    return(apiProperty);
                }

                // Complex attribute, children are DomAttribute nodes.
                return(CreateApiPropertyFromDomAttribute(domAttribute));
            })
                                .ToList();

            var apiObject = new ApiObject(apiProperties);

            return(apiObject);
        }