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


C# ResourceType.RemoveKeyProperties方法代码示例

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


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

示例1: BuildTypeProperties

        private static void BuildTypeProperties(
            ResourceType parentResourceType,
            ProviderMetadataCacheItem metadataCacheItem,
            Queue<ResourceType> unvisitedTypes)
        {
            Debug.Assert(parentResourceType != null, "parentResourceType != null");
            Debug.Assert(metadataCacheItem != null, "metadataCacheItem != null");
            Debug.Assert(unvisitedTypes != null, "unvisitedTypes != null");

            BindingFlags bindingFlags = WebUtil.PublicInstanceBindingFlags;

            // For non root types, we should only look for properties that are declared for this type
            if (parentResourceType.BaseType != null)
            {
                bindingFlags = bindingFlags | BindingFlags.DeclaredOnly;
            }

            HashSet<string> propertiesToBeIgnored = new HashSet<string>(IgnorePropertiesAttribute.GetProperties(parentResourceType.InstanceType, false /*inherit*/, bindingFlags), StringComparer.Ordinal);
            Debug.Assert(parentResourceType.IsOpenType == false, "ReflectionServiceProvider does not support Open types.");

            HashSet<string> etagPropertyNames = new HashSet<string>(LoadETagProperties(parentResourceType), StringComparer.Ordinal);

            ResourceKeyKind keyKind = (ResourceKeyKind)Int32.MaxValue;
            PropertyInfo[] properties = parentResourceType.InstanceType.GetProperties(bindingFlags);

            // Should not allow System.Object on server
            // The general fix for this bug is to not support any resource type that doesn't have
            // any publically visible properties, including System.object and also custom types which don't have any properties.
            if (!properties.Any() && parentResourceType.BaseType == null)
            {
                throw new NotSupportedException(Strings.ReflectionProvider_ResourceTypeHasNoPublicallyVisibleProperties(parentResourceType.FullName));
            }

            foreach (PropertyInfo property in properties)
            {
                // Ignore the properties which are specified in the IgnoreProperties attribute
                if (propertiesToBeIgnored.Contains(property.Name))
                {
                    continue;
                }

                if (property.CanRead && property.GetIndexParameters().Length == 0)
                {
                    ResourcePropertyKind kind = (ResourcePropertyKind)(-1);
                    ResourceType resourceType;
                    Type resourcePropertyType = property.PropertyType;
                    bool collection = false;

                    if (!TryGetType(metadataCacheItem, resourcePropertyType, out resourceType))
                    {
                        Type collectionType = GetIEnumerableElement(property.PropertyType);
                        if (collectionType != null)
                        {
                            TryGetType(metadataCacheItem, collectionType, out resourceType);

                            // Even if the above method returns false, we should set the
                            // following variable appropriately, so that we can use them below
                            collection = true;
                            resourcePropertyType = collectionType;
                        }
                    }

                    if (resourceType != null)
                    {
                        #region Already Known Type
                        if (resourceType.ResourceTypeKind == ResourceTypeKind.Primitive)
                        {
                            if (collection)
                            {
                                // If it's a collection it can't be a key property (we don't allow collection properties as key)
                                kind = ResourcePropertyKind.Collection;
                            }
                            else
                            {
                                ResourceKeyKind currentKeyKind;
                                if (parentResourceType.BaseType == null && parentResourceType.ResourceTypeKind == ResourceTypeKind.EntityType && IsPropertyKeyProperty(property, out currentKeyKind))
                                {
                                    // Check for key property only on root types, since keys must be defined on the root types
                                    if ((int)currentKeyKind < (int)keyKind)
                                    {
                                        if (parentResourceType.KeyProperties.Count != 0)
                                        {
                                            // Remove the existing property as key property - mark it as non key property
                                            parentResourceType.RemoveKeyProperties();
                                        }

                                        keyKind = currentKeyKind;
                                        kind = ResourcePropertyKind.Key | ResourcePropertyKind.Primitive;
                                    }
                                    else if ((int)currentKeyKind == (int)keyKind)
                                    {
                                        Debug.Assert(currentKeyKind == ResourceKeyKind.AttributedKey, "This is the only way of specifying composite keys");
                                        kind = ResourcePropertyKind.Key | ResourcePropertyKind.Primitive;
                                    }
                                    else
                                    {
                                        kind = ResourcePropertyKind.Primitive;
                                    }
                                }
                                else
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:ReflectionServiceProvider.cs


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