本文整理汇总了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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}