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


C# Type.IsCollection方法代码示例

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


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

示例1: Convert

        /// <summary>
        /// Convert the string representation to the destination type
        /// </summary>
        /// <param name="input">Input string</param>
        /// <param name="destinationType">Destination type</param>
        /// <param name="context">Current context</param>
        /// <returns>Converted object of the destination type</returns>
        public object Convert(string input, Type destinationType, BindingContext context)
        {
            if (string.IsNullOrEmpty(input))
            {
                return null;
            }

            var items = input.Split(',');

            // Strategy, schmategy ;-)
            if (destinationType.IsCollection())
            {
                return this.ConvertCollection(items, destinationType, context);
            }

            if (destinationType.IsArray())
            {
                return this.ConvertArray(items, destinationType, context);
            }

            if (destinationType.IsEnumerable())
            {
                return this.ConvertEnumerable(items, destinationType, context);
            }

            return null;
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:34,代码来源:CollectionConverter.cs

示例2: NavigationPropertyConfiguration

        public NavigationPropertyConfiguration(PropertyInfo property, EdmMultiplicity multiplicity, IEntityTypeConfiguration declaringType)
            : base(property, declaringType)
        {
            if (property == null)
            {
                throw Error.ArgumentNull("property");
            }

            Multiplicity = multiplicity;

            _relatedType = property.PropertyType;
            if (multiplicity == EdmMultiplicity.Many)
            {
                Type elementType;
                if (!_relatedType.IsCollection(out elementType))
                {
                    throw Error.InvalidOperation(SRResources.ManyToManyNavigationPropertyMustReturnCollection, property.Name, property.ReflectedType.Name);
                }

                _relatedType = elementType;
            }
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:22,代码来源:NavigationPropertyConfiguration.cs

示例3: NonbindingParameterConfigurationSupportsParameterCollectionTypeAs

        public void NonbindingParameterConfigurationSupportsParameterCollectionTypeAs(Type type, bool isNullable)
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            builder.EntityType<Customer>();
            builder.ComplexType<Address>();
            builder.EnumType<Color>();

            Type elementType;
            Assert.True(type.IsCollection(out elementType));

            // Act
            Type underlyingType = TypeHelper.GetUnderlyingTypeOrSelf(elementType);
            IEdmTypeConfiguration elementTypeConfiguration = builder.GetTypeConfigurationOrNull(underlyingType);
            CollectionTypeConfiguration collectionType = new CollectionTypeConfiguration(elementTypeConfiguration,
                typeof(IEnumerable<>).MakeGenericType(elementType));

            NonbindingParameterConfiguration parameter = new NonbindingParameterConfiguration("name", collectionType);

            // Assert
            Assert.Equal(isNullable, parameter.OptionalParameter);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:22,代码来源:ParameterConfigurationTest.cs

示例4: GetEdmObjectPayloadKind

        private static ODataPayloadKind? GetEdmObjectPayloadKind(Type type)
        {
            Type elementType;
            if (type.IsCollection(out elementType))
            {
                if (typeof(IEdmComplexObject).IsAssignableFrom(elementType))
                {
                    return ODataPayloadKind.Collection;
                }
                else if (typeof(IEdmEntityObject).IsAssignableFrom(elementType))
                {
                    return ODataPayloadKind.Feed;
                }
            }
            else
            {
                if (typeof(IEdmComplexObject).IsAssignableFrom(elementType))
                {
                    return ODataPayloadKind.Property;
                }
                else if (typeof(IEdmEntityObject).IsAssignableFrom(elementType))
                {
                    return ODataPayloadKind.Entry;
                }
            }

            return null;
        }
开发者ID:sstrazan,项目名称:aspnetwebstack,代码行数:28,代码来源:ODataMediaTypeFormatter.cs

示例5: CanWriteType

        /// <inheritdoc/>
        public override bool CanWriteType(Type type)
        {
            if (type == null)
            {
                throw Error.ArgumentNull("type");
            }

            if (Request != null)
            {
                IEdmModel model = Request.GetEdmModel();
                if (model != null)
                {
                    ODataPayloadKind? payloadKind;

                    Type elementType;
                    if (typeof(IEdmObject).IsAssignableFrom(type) ||
                        (type.IsCollection(out elementType) && typeof(IEdmObject).IsAssignableFrom(elementType)))
                    {
                        payloadKind = GetEdmObjectPayloadKind(type);
                    }
                    else
                    {
                        payloadKind = GetClrObjectResponsePayloadKind(type, model);
                    }

                    return payloadKind == null ? false : _payloadKinds.Contains(payloadKind.Value);
                }
            }

            return false;
        }
开发者ID:sstrazan,项目名称:aspnetwebstack,代码行数:32,代码来源:ODataMediaTypeFormatter.cs

示例6: GetEdmObjectPayloadKind

        /// <summary>
        /// This method is to get payload kind for untyped scenario.
        /// </summary>
        private ODataPayloadKind? GetEdmObjectPayloadKind(Type type)
        {
            if (ODataCountMediaTypeMapping.IsCountRequest(Request))
            {
                return ODataPayloadKind.Value;
            }

            Type elementType;
            if (type.IsCollection(out elementType))
            {
                if (typeof(IEdmComplexObject).IsAssignableFrom(elementType) || typeof(IEdmEnumObject).IsAssignableFrom(elementType))
                {
                    return ODataPayloadKind.Collection;
                }
                else if (typeof(IEdmEntityObject).IsAssignableFrom(elementType))
                {
                    return ODataPayloadKind.Feed;
                }
                else if (typeof(IEdmChangedObject).IsAssignableFrom(elementType))
                {
                    return ODataPayloadKind.Delta;
                }
            }
            else
            {
                if (typeof(IEdmComplexObject).IsAssignableFrom(elementType) || typeof(IEdmEnumObject).IsAssignableFrom(elementType))
                {
                    return ODataPayloadKind.Property;
                }
                else if (typeof(IEdmEntityObject).IsAssignableFrom(elementType))
                {
                    return ODataPayloadKind.Entry;
                }
            }

            return null;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:40,代码来源:ODataMediaTypeFormatter.cs

示例7: CanConvertTo

 /// <summary>
 /// Whether the converter can convert to the destination type
 /// </summary>
 /// <param name="destinationType">Destination type</param>
 /// <param name="context">The current binding context</param>
 /// <returns>True if conversion supported, false otherwise</returns>
 public bool CanConvertTo(Type destinationType, BindingContext context)
 {
     return destinationType.IsCollection() || destinationType.IsEnumerable() || destinationType.IsArray();
 }
开发者ID:Borzoo,项目名称:Nancy,代码行数:10,代码来源:CollectionConverter.cs


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