public static void MapClrAttributesToDomResource(this IResourceType resourceType, DomReadWriteResource domResource, object clrResource, Func <string, string, bool> attributePredicate)
        {
            Contract.Requires(resourceType != null);
            Contract.Requires(domResource != null);

            if (clrResource == null)
            {
                return;
            }

            var serviceModel  = domResource.GetServiceModel();
            var domAttributes = domResource.CreateAndAddNode(() => DomAttributes.Create());

            var apiType = resourceType.ResourceIdentityInfo.ApiType;
            var attributeInfoCollection = resourceType.AttributesInfo.Collection;

            foreach (var attributeInfo in attributeInfoCollection)
            {
                var apiField = attributeInfo.ApiPropertyName;
                if (attributePredicate != null && attributePredicate(apiType, apiField) == false)
                {
                    // Skip adding this attribute.
                    continue;
                }

                var localAttributeInfo = attributeInfo;
                domAttributes.CreateAndAddNode(() => DomAttribute.CreateFromClrResource(serviceModel, localAttributeInfo, clrResource));
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Factory Methods
        public static DomAttribute CreateFromApiResource(IAttributeInfo attributeInfo, IGetAttributes apiGetAttributes)
        {
            Contract.Requires(attributeInfo != null);
            Contract.Requires(apiGetAttributes != null);

            var apiAttribute    = attributeInfo.GetApiAttribute(apiGetAttributes);
            var apiPropertyName = attributeInfo.ApiPropertyName;

            var clrPropertyType = attributeInfo.ClrPropertyType;
            var clrPropertyName = attributeInfo.ClrPropertyName;
            var clrAttribute    = apiAttribute.ToClrObject(clrPropertyType);

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

            return(domAttribute);
        }
Esempio n. 5
0
        private static void AddCollectionOfComplexTypeAttributes(IServiceModel serviceModel, IAttributeInfo attributeInfo, DomAttribute domAttribute)
        {
            Contract.Requires(serviceModel != null);
            Contract.Requires(attributeInfo != null);
            Contract.Requires(domAttribute != null);

            var clrAttribute = domAttribute.ClrAttribute;

            if (clrAttribute == null)
            {
                return;
            }

            var clrCollectionItemType               = attributeInfo.ClrCollectionItemType;
            var complexType                         = serviceModel.GetComplexType(clrCollectionItemType);
            var complexTypeAttributesInfo           = complexType.AttributesInfo;
            var complexTypeAttributesInfoCollection = complexTypeAttributesInfo.Collection;

            var index         = 0;
            var clrCollection = (IEnumerable <object>)clrAttribute;

            foreach (var clrCollectionItem in clrCollection.EmptyIfNull())
            {
                // Add indexed complex object to index node.
                var localClrObject = clrCollectionItem;
                if (localClrObject == null)
                {
                    continue;
                }

                // Add an index node.
                var domIndex = domAttribute.CreateAndAddNode(() => DomIndex.Create(index++));

                // ReSharper disable once PossibleMultipleEnumeration
                foreach (var complexTypeAttributeInfo in complexTypeAttributesInfoCollection)
                {
                    var localAttributeInfo = complexTypeAttributeInfo;
                    domIndex.CreateAndAddNode(() => DomAttribute.CreateFromClrResource(serviceModel, localAttributeInfo, localClrObject));
                }
            }
        }
        public static void MapClrAttributesToDomResource(this IResourceType resourceType, DomReadWriteResource domResource, object clrResource)
        {
            Contract.Requires(resourceType != null);
            Contract.Requires(domResource != null);

            if (clrResource == null)
            {
                return;
            }

            var serviceModel  = domResource.GetServiceModel();
            var domAttributes = domResource.CreateAndAddNode(() => DomAttributes.Create());

            var attributeInfoCollection = resourceType.AttributesInfo.Collection;

            foreach (var attributeInfo in attributeInfoCollection)
            {
                var localAttributeInfo = attributeInfo;
                domAttributes.CreateAndAddNode(() => DomAttribute.CreateFromClrResource(serviceModel, localAttributeInfo, clrResource));
            }
        }
        public static void MapClrAttributeToDomAttributes(this IResourceType resourceType, DomAttributes domAttributes, string clrAttributeName, object clrAttribute)
        {
            Contract.Requires(resourceType != null);
            Contract.Requires(domAttributes != null);
            Contract.Requires(String.IsNullOrWhiteSpace(clrAttributeName) == false);

            if (clrAttribute == null)
            {
                return;
            }

            var serviceModel = domAttributes.GetServiceModel();
            var attribute    = resourceType.GetClrAttributeInfo(clrAttributeName);
            var domAttribute = DomAttribute.CreateFromClrAttribute(serviceModel, attribute, clrAttribute);

            if (domAttribute == null)
            {
                return;
            }

            domAttributes.Add(domAttribute);
        }
Esempio n. 8
0
        private static void AddComplexTypeAttributes(IServiceModel serviceModel, IPropertyInfo attributeInfo, DomAttribute domAttribute)
        {
            Contract.Requires(serviceModel != null);
            Contract.Requires(attributeInfo != null);
            Contract.Requires(domAttribute != null);

            var clrPropertyType = attributeInfo.ClrPropertyType;
            var clrAttribute    = domAttribute.ClrAttribute;

            if (clrAttribute == null)
            {
                return;
            }

            var complexType = serviceModel.GetComplexType(clrPropertyType);
            var complexTypeAttributesInfo           = complexType.AttributesInfo;
            var complexTypeAttributesInfoCollection = complexTypeAttributesInfo.Collection;

            foreach (var complexTypeAttributeInfo in complexTypeAttributesInfoCollection)
            {
                var localAttributeInfo = complexTypeAttributeInfo;
                domAttribute.CreateAndAddNode(() => DomAttribute.CreateFromClrResource(serviceModel, localAttributeInfo, clrAttribute));
            }
        }