本文整理汇总了C#中IEdmTypeReference.AsCollection方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.AsCollection方法的具体用法?C# IEdmTypeReference.AsCollection怎么用?C# IEdmTypeReference.AsCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.AsCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadInline
/// <inheritdoc />
public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
{
if (item == null)
{
return null;
}
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
if (!edmType.IsCollection() || !edmType.AsCollection().ElementType().IsEntity())
{
throw Error.Argument("edmType", SRResources.TypeMustBeEntityCollection, edmType.ToTraceString(), typeof(IEdmEntityType).Name);
}
IEdmEntityTypeReference elementType = edmType.AsCollection().ElementType().AsEntity();
ODataFeedWithEntries feed = item as ODataFeedWithEntries;
if (feed == null)
{
throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataFeedWithEntries).Name);
}
// Recursion guard to avoid stack overflows
RuntimeHelpers.EnsureSufficientExecutionStack();
return ReadFeed(feed, elementType, readContext);
}
示例2: CreateEdmTypeSerializer
public override ODataSerializer CreateEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
switch (edmType.TypeKind())
{
case EdmTypeKind.Primitive:
return new ODataPrimitiveSerializer(edmType.AsPrimitive());
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.ElementType().IsEntity())
{
return new ODataFeedSerializer(collectionType, this);
}
else
{
return new ODataCollectionSerializer(collectionType, this);
}
case EdmTypeKind.Complex:
return new ODataComplexTypeSerializer(edmType.AsComplex(), this);
case EdmTypeKind.Entity:
return new ODataEntityTypeSerializer(edmType.AsEntity(), this);
default:
throw Error.InvalidOperation(SRResources.TypeCannotBeSerialized, edmType.ToTraceString(), typeof(ODataMediaTypeFormatter).Name);
}
}
示例3: CreateDeserializer
protected override ODataEntryDeserializer CreateDeserializer(IEdmTypeReference edmType)
{
if (edmType != null)
{
switch (edmType.TypeKind())
{
case EdmTypeKind.Entity:
return new ODataEntityDeserializer(edmType.AsEntity(), this);
case EdmTypeKind.Primitive:
return new ODataPrimitiveDeserializer(edmType.AsPrimitive());
case EdmTypeKind.Complex:
return new ODataComplexTypeDeserializer(edmType.AsComplex(), this);
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.ElementType().IsEntity())
{
return new ODataFeedDeserializer(collectionType, this);
}
else
{
return new ODataCollectionDeserializer(collectionType, this);
}
}
}
return null;
}
示例4: GetEdmTypeDeserializer
/// <inheritdoc />
public override ODataEdmTypeDeserializer GetEdmTypeDeserializer(IEdmTypeReference edmType)
{
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
switch (edmType.TypeKind())
{
case EdmTypeKind.Entity:
return _entityDeserializer;
case EdmTypeKind.Primitive:
return _primitiveDeserializer;
case EdmTypeKind.Complex:
return _complexDeserializer;
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.ElementType().IsEntity())
{
return _feedDeserializer;
}
else
{
return _collectionDeserializer;
}
default:
return null;
}
}
示例5: CreateEdmTypeSerializer
/// <summary>
/// Creates a new instance of the <see cref="ODataEdmTypeSerializer"/> for the given edm type.
/// </summary>
/// <param name="edmType">The <see cref="IEdmTypeReference"/>.</param>
/// <returns>The constructed <see cref="ODataEdmTypeSerializer"/>.</returns>
public virtual ODataEdmTypeSerializer CreateEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
switch (edmType.TypeKind())
{
case EdmTypeKind.Primitive:
return new ODataPrimitiveSerializer(edmType.AsPrimitive());
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.ElementType().IsEntity())
{
return new ODataFeedSerializer(collectionType, this);
}
else
{
return new ODataCollectionSerializer(collectionType, this);
}
case EdmTypeKind.Complex:
return new ODataComplexTypeSerializer(edmType.AsComplex(), this);
case EdmTypeKind.Entity:
return new ODataEntityTypeSerializer(edmType.AsEntity(), this);
default:
return null;
}
}
示例6: ReadInline
/// <inheritdoc />
public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
{
if (item == null)
{
return null;
}
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
if (!edmType.IsCollection())
{
throw new SerializationException(
Error.Format(SRResources.TypeCannotBeDeserialized, edmType.ToTraceString(), typeof(ODataMediaTypeFormatter)));
}
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
IEdmTypeReference elementType = collectionType.ElementType();
ODataCollectionValue collection = item as ODataCollectionValue;
if (collection == null)
{
throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataCollectionValue).Name);
}
// Recursion guard to avoid stack overflows
RuntimeHelpers.EnsureSufficientExecutionStack();
return ReadCollectionValue(collection, elementType, readContext);
}
示例7: ReadInline
/// <inheritdoc />
public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
{
if (item == null)
{
return null;
}
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
if (!edmType.IsCollection())
{
throw new SerializationException(
Error.Format(SRResources.TypeCannotBeDeserialized, edmType.ToTraceString(), typeof(ODataMediaTypeFormatter)));
}
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
IEdmTypeReference elementType = collectionType.ElementType();
ODataCollectionValue collection = item as ODataCollectionValue;
if (collection == null)
{
throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataCollectionValue).Name);
}
// Recursion guard to avoid stack overflows
RuntimeHelpers.EnsureSufficientExecutionStack();
IEnumerable result = ReadCollectionValue(collection, elementType, readContext);
if (result != null)
{
if (readContext.IsUntyped && elementType.IsComplex())
{
EdmComplexObjectCollection complexCollection = new EdmComplexObjectCollection(collectionType);
foreach (EdmComplexObject complexObject in result)
{
complexCollection.Add(complexObject);
}
return complexCollection;
}
else if (readContext.IsUntyped && elementType.IsEnum())
{
EdmEnumObjectCollection enumCollection = new EdmEnumObjectCollection(collectionType);
foreach (EdmEnumObject enumObject in result)
{
enumCollection.Add(enumObject);
}
return enumCollection;
}
else
{
Type elementClrType = EdmLibHelpers.GetClrType(elementType, readContext.Model);
IEnumerable castedResult = _castMethodInfo.MakeGenericMethod(elementClrType).Invoke(null, new object[] { result }) as IEnumerable;
return castedResult;
}
}
return null;
}
示例8: ReadWithExpectedType
/// <summary>
/// Reads a value from the message reader.
/// </summary>
/// <param name="expectedClientType">The expected client type being materialized into.</param>
/// <param name="expectedReaderType">The expected type for the underlying reader.</param>
protected override void ReadWithExpectedType(IEdmTypeReference expectedClientType, IEdmTypeReference expectedReaderType)
{
ODataProperty property = this.messageReader.ReadProperty(expectedReaderType);
Type underlyingExpectedType = Nullable.GetUnderlyingType(this.ExpectedType) ?? this.ExpectedType;
object propertyValue = property.Value;
if (expectedClientType.IsCollection())
{
Debug.Assert(WebUtil.IsCLRTypeCollection(underlyingExpectedType, this.MaterializerContext.Model) || (SingleResult.HasValue && !SingleResult.Value), "expected type must be collection or single result must be false");
// We are here for two cases:
// (1) Something like Execute<ICollection<T>>, in which case the underlyingExpectedType is ICollection<T>
// (2) Execute<T> with the bool singleValue = false, in which case underlyingExpectedType is T
Type collectionItemType = this.ExpectedType;
Type collectionICollectionType = ClientTypeUtil.GetImplementationType(underlyingExpectedType, typeof(ICollection<>));
object collectionInstance;
if (collectionICollectionType != null)
{
// Case 1
collectionItemType = collectionICollectionType.GetGenericArguments()[0];
collectionInstance = this.CollectionValueMaterializationPolicy.CreateCollectionPropertyInstance(property, underlyingExpectedType);
}
else
{
// Case 2
collectionICollectionType = typeof(ICollection<>).MakeGenericType(new Type[] { collectionItemType });
collectionInstance = this.CollectionValueMaterializationPolicy.CreateCollectionPropertyInstance(property, collectionICollectionType);
}
bool isElementNullable = expectedClientType.AsCollection().ElementType().IsNullable;
this.CollectionValueMaterializationPolicy.ApplyCollectionDataValues(
property,
collectionInstance,
collectionItemType,
ClientTypeUtil.GetAddToCollectionDelegate(collectionICollectionType),
isElementNullable);
this.currentValue = collectionInstance;
}
else if (expectedClientType.IsComplex())
{
ODataComplexValue complexValue = propertyValue as ODataComplexValue;
Debug.Assert(this.MaterializerContext.Model.GetOrCreateEdmType(underlyingExpectedType).ToEdmTypeReference(false).IsComplex(), "expectedType must be complex type");
this.ComplexValueMaterializationPolicy.MaterializeComplexTypeProperty(underlyingExpectedType, complexValue);
this.currentValue = complexValue.GetMaterializedValue();
}
else if (expectedClientType.IsEnum())
{
this.currentValue = this.EnumValueMaterializationPolicy.MaterializeEnumTypeProperty(underlyingExpectedType, property);
}
else
{
Debug.Assert(this.MaterializerContext.Model.GetOrCreateEdmType(underlyingExpectedType).ToEdmTypeReference(false).IsPrimitive(), "expectedType must be primitive type");
this.currentValue = this.PrimitivePropertyConverter.ConvertPrimitiveValue(property.Value, this.ExpectedType);
}
}
示例9: SetDynamicProperty
internal static void SetDynamicProperty(object resource, IEdmStructuredTypeReference resourceType,
EdmTypeKind propertyKind, string propertyName, object propertyValue, IEdmTypeReference propertyType,
ODataDeserializerContext readContext, AssembliesResolver assembliesResolver)
{
if (propertyKind == EdmTypeKind.Collection && propertyValue.GetType() != typeof(EdmComplexObjectCollection)
&& propertyValue.GetType() != typeof(EdmEnumObjectCollection))
{
SetDynamicCollectionProperty(resource, propertyName, propertyValue, propertyType.AsCollection(),
resourceType.StructuredDefinition(), readContext, assembliesResolver);
}
else
{
SetDynamicProperty(resource, propertyName, propertyValue, resourceType.StructuredDefinition(),
readContext);
}
}
示例10: GetEntityType
private static IEdmEntityTypeReference GetEntityType(IEdmTypeReference feedType)
{
if (feedType.IsCollection())
{
IEdmTypeReference elementType = feedType.AsCollection().ElementType();
if (elementType.IsEntity())
{
return elementType.AsEntity();
}
}
string message = string.Format(
CultureInfo.InvariantCulture,
"{0} cannot write an object of type '{1}'.",
typeof(ODataDomainFeedSerializer).Name,
feedType.FullName());
throw new SerializationException(message);
}
示例11: SetDynamicProperty
internal static void SetDynamicProperty(object resource, IEdmStructuredTypeReference resourceType,
EdmTypeKind propertyKind, string propertyName, object propertyValue, IEdmTypeReference propertyType,
ODataDeserializerContext readContext)
{
if (propertyKind == EdmTypeKind.Collection)
{
SetDynamicCollectionProperty(resource, propertyName, propertyValue, propertyType.AsCollection(),
resourceType.StructuredDefinition(), readContext);
}
else
{
if (propertyKind == EdmTypeKind.Enum)
{
propertyValue = ConvertDynamicEnumValue(propertyValue, readContext);
}
SetDynamicProperty(resource, propertyName, propertyValue, resourceType.StructuredDefinition(),
readContext);
}
}
示例12: GetEdmTypeSerializer
/// <inheritdoc />
public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
switch (edmType.TypeKind())
{
case EdmTypeKind.Enum:
return _enumSerializer;
case EdmTypeKind.Primitive:
return _primitiveSerializer;
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.Definition.IsDeltaFeed())
{
return _deltaFeedSerializer;
}
else if (collectionType.ElementType().IsEntity())
{
return _feedSerializer;
}
else
{
return _collectionSerializer;
}
case EdmTypeKind.Complex:
return _complexTypeSerializer;
case EdmTypeKind.Entity:
return _entityTypeSerializer;
default:
return null;
}
}
示例13: TryWriteAggregationResult
private bool TryWriteAggregationResult(
object graph,
Type type,
ODataMessageWriter messageWriter,
ODataSerializerContext writeContext,
IEdmTypeReference resourceSetType)
{
if (typeof(IEnumerable<DynamicTypeWrapper>).IsAssignableFrom(type))
{
IEdmTypeReference elementType = resourceSetType.AsCollection().ElementType();
if (elementType.IsEntity())
{
var entitySet = writeContext.NavigationSource as IEdmEntitySetBase;
var entityType = elementType.AsEntity();
var writer = messageWriter.CreateODataResourceSetWriter(entitySet, entityType.EntityDefinition());
WriteObjectInline(graph, resourceSetType, writer, writeContext);
return true;
}
}
return false;
}
示例14: GetEdmTypeSerializer
/// <summary>
/// Gets the serializer for the given EDM type reference.
/// </summary>
/// <param name="edmType">The EDM type reference involved in the serializer.</param>
/// <returns>The serializer instance.</returns>
public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType.IsEntity())
{
return this.entityTypeSerializer;
}
if (edmType.IsComplex())
{
return this.complexTypeSerializer;
}
if (edmType.IsPrimitive())
{
return this.primitiveSerializer;
}
if (edmType.IsEnum())
{
return this.enumSerializer;
}
if (edmType.IsCollection())
{
if (edmType.AsCollection().ElementType().IsEntity())
{
return this.feedSerializer;
}
return this.collectionSerializer;
}
return base.GetEdmTypeSerializer(edmType);
}
示例15: IsEntityOrFeed
private static bool IsEntityOrFeed(IEdmTypeReference type)
{
Contract.Assert(type != null);
return type.IsEntity() ||
(type.IsCollection() && type.AsCollection().ElementType().IsEntity());
}