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));
            }
        }
        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));
            }
        }
Example #3
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Factory Methods
        public static DomAttributes Create(params Node <DomNodeType>[] domNodes)
        {
            var domAttributes = new DomAttributes(domNodes);

            return(domAttributes);
        }
        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);
        }