当前位置: 首页>>代码示例>>C#>>正文


C# ResourceType.IsAssignableFrom方法代码示例

本文整理汇总了C#中Microsoft.OData.Service.Providers.ResourceType.IsAssignableFrom方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceType.IsAssignableFrom方法的具体用法?C# ResourceType.IsAssignableFrom怎么用?C# ResourceType.IsAssignableFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Service.Providers.ResourceType的用法示例。


在下文中一共展示了ResourceType.IsAssignableFrom方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResourceAssociationSetEnd

        /// <summary>Creates a new instance of the <see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> class.</summary>
        /// <param name="resourceSet">The resource set to which the <see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> end belongs.</param>
        /// <param name="resourceType">The resource type to which the <see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> end belongs.</param>
        /// <param name="resourceProperty">The resource property that returns the <see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> end.</param>
        public ResourceAssociationSetEnd(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            WebUtil.CheckArgumentNull(resourceSet, "resourceSet");
            WebUtil.CheckArgumentNull(resourceType, "resourceType");

            if (resourceProperty != null && (resourceType.TryResolvePropertyName(resourceProperty.Name) == null || resourceProperty.TypeKind != ResourceTypeKind.EntityType))
            {
                throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourcePropertyMustBeNavigationPropertyOnResourceType);
            }

            if (!resourceSet.ResourceType.IsAssignableFrom(resourceType) && !resourceType.IsAssignableFrom(resourceSet.ResourceType))
            {
                throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourceTypeMustBeAssignableToResourceSet);
            }

            this.resourceSet = resourceSet;
            this.resourceType = resourceType;

            // Note that for the TargetEnd, resourceProperty can be null.
            this.resourceProperty = resourceProperty;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:25,代码来源:ResourceAssociationSetEnd.cs

示例2: VerifyPropertyMismatchAndExpandSelectMismatchScenario

        /// <summary>
        /// Verify that the property referred by the existing node and the new segment are both open properties or declared properties
        /// and if the existing node is an expand node, make sure that the target resource types are the same.
        /// </summary>
        /// <param name="existingNode">Existing node with the same property name.</param>
        /// <param name="property">ResourceProperty instance for the property refered by the new segment.</param>
        /// <param name="targetResourceType">TargetResourceType for the new segment.</param>
        /// <param name="expandNode">true if the existingNode is an expand node.</param>
        private static void VerifyPropertyMismatchAndExpandSelectMismatchScenario(ProjectionNode existingNode, ResourceProperty property, ResourceType targetResourceType, bool expandNode)
        {
            Debug.Assert(
                existingNode.TargetResourceType.IsAssignableFrom(targetResourceType) ||
                targetResourceType.IsAssignableFrom(existingNode.TargetResourceType),
                "This method must be called if the existingNode and targetResourceType are in the same inheritance chain");
            Debug.Assert(!expandNode || existingNode is ExpandedProjectionNode, "If expandNode is true, then the existingNode must be an ExpandedProjectionNode");

            if (property != existingNode.Property)
            {
                // If the property are not the same - it means one of them must be null.
                // This is only possible if super type is open and the property resolves to an open property.
                Debug.Assert(property == null || existingNode.Property == null, "One of the properties must be null, since the types belong to the same inheritance chain, and cannot have different property instance from a given property name");

                // Currently we do not support scenarios where one refers to the open property on the supertype
                // and declared property on the sub type.
                throw DataServiceException.CreateBadRequestError(
                    Strings.RequestQueryProcessor_CannotSpecifyOpenPropertyAndDeclaredPropertyAtTheSameTime(
                        existingNode.PropertyName,
                        property == null ? targetResourceType.FullName : existingNode.TargetResourceType.FullName,
                        property == null ? existingNode.TargetResourceType.FullName : targetResourceType.FullName));
            }
            
            if (!ResourceType.CompareReferences(targetResourceType, existingNode.TargetResourceType) && expandNode)
            {
                // If expand and select are specified on the same property within a given type
                // hierarchy, currently we enforce that they must be specified on the same type
                throw DataServiceException.CreateBadRequestError(
                    Strings.RequestQueryProcessor_SelectAndExpandCannotBeSpecifiedTogether(existingNode.PropertyName));
            }
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:39,代码来源:ExpandedProjectionNode.cs

示例3: ApplyPropertyToExistingNode

        /// <summary>
        /// Whether the given property can be applied to the existing node.
        /// </summary>
        /// <param name="existingNode">Existing node with the same property name.</param>
        /// <param name="property">ResourceProperty instance for the property refered by the new segment.</param>
        /// <param name="targetResourceType">TargetResourceType for the new segment.</param>
        /// <returns>true if the given property can be applied to the existing node, otherwise returns false.</returns>
        /// <remarks>In case this function returns true, it might modify the TargetResourceType property of the existing node.</remarks>
        private static bool ApplyPropertyToExistingNode(ProjectionNode existingNode, ResourceProperty property, ResourceType targetResourceType)
        {
            Debug.Assert(existingNode != null, "existingNode != null");
            Debug.Assert(property == null || property.Name == existingNode.PropertyName, "property == null || property.Name == existingNode.PropertyName");

            // This is just quicker way of determining if declared property belongs to different sub-trees.
            // Since any given property can be declared once in a chain of derived types, if the property instances
            // are not the same, we can assume that they do not belong to the same hierarchy chain.
            // Even if we do not have this check, everything will just work, since we check the type assignability.
            if (property != null && existingNode.Property != null && property != existingNode.Property)
            {
                return false;
            }

            ExpandedProjectionNode expansionNode = existingNode as ExpandedProjectionNode;

            // If the target resource type of the new segment is a super type, we might 
            // need to update the target resource type of the existing node.
            // Since IsAssignableFrom returns true when they are equal, it isn't require
            // to do anything, but if we do, it should still work.
            if (targetResourceType.IsAssignableFrom(existingNode.TargetResourceType))
            {
                ExpandedProjectionNode.VerifyPropertyMismatchAndExpandSelectMismatchScenario(
                    existingNode,
                    property,
                    targetResourceType,
                    expansionNode != null);

                existingNode.TargetResourceType = targetResourceType;
                return true;
            }

            // If the existing node is already a super type, then there is nothing to do
            // other than validating the error scenarios.
            if (existingNode.TargetResourceType.IsAssignableFrom(targetResourceType))
            {
                ExpandedProjectionNode.VerifyPropertyMismatchAndExpandSelectMismatchScenario(
                    existingNode,
                    property,
                    targetResourceType,
                    expansionNode != null);
                return true;
            }

            return false;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:54,代码来源:ExpandedProjectionNode.cs

示例4: GetDerivedTypes

 public IEnumerable<ResourceType> GetDerivedTypes(ResourceType resourceType)
 {
     return this.resourceTypes.Where(type => resourceType.IsAssignableFrom(type) && type != resourceType);
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:4,代码来源:DataServiceProviderSimulator.cs


注:本文中的Microsoft.OData.Service.Providers.ResourceType.IsAssignableFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。