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));
            }
        }
Beispiel #2
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));
            }
        }
Beispiel #4
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));
            }
        }