internal static IEdmTypeReference GetExpectedPayloadType(Type type, ODataPath path, IEdmModel model) { IEdmTypeReference expectedPayloadType = null; if (typeof(IEdmObject).IsAssignableFrom(type)) { // typeless mode. figure out the expected payload type from the OData Path. IEdmType edmType = path.EdmType; if (edmType != null) { expectedPayloadType = EdmLibHelpers.ToEdmTypeReference(edmType, isNullable: false); if (expectedPayloadType.TypeKind() == EdmTypeKind.Collection) { IEdmTypeReference elementType = expectedPayloadType.AsCollection().ElementType(); if (elementType.IsEntity()) { // collection of entities cannot be CREATE/UPDATEd. Instead, the request would contain a single entry. expectedPayloadType = elementType; } } } } else { TryGetInnerTypeForDelta(ref type); expectedPayloadType = model.GetEdmTypeReference(type); } return(expectedPayloadType); }
private static ODataDeserializer GetDeserializer(Type type, ODataPath path, IEdmModel model, ODataDeserializerProvider deserializerProvider) { if (typeof(IEdmObject).IsAssignableFrom(type)) { // typeless mode. figure out the expected payload type from the OData Path. IEdmType edmType = path.EdmType; if (edmType != null) { IEdmTypeReference expectedPayloadType = EdmLibHelpers.ToEdmTypeReference(edmType, isNullable: false); if (expectedPayloadType.TypeKind() == EdmTypeKind.Collection) { IEdmTypeReference elementType = expectedPayloadType.AsCollection().ElementType(); if (elementType.IsEntity()) { // collection of entities cannot be CREATE/UPDATEd. Instead, the request would contain a single entry. expectedPayloadType = elementType; } } if (expectedPayloadType != null) { return(deserializerProvider.GetEdmTypeDeserializer(expectedPayloadType)); } } } else { TryGetInnerTypeForDelta(ref type); return(deserializerProvider.GetODataDeserializer(model, type)); } return(null); }
public void ToEdmTypeReference_InstantiatesRightEdmTypeReference(IEdmType edmType, bool isNullable, Type expectedType) { IEdmTypeReference result = EdmLibHelpers.ToEdmTypeReference(edmType, isNullable); Assert.Equal(isNullable, result.IsNullable); Assert.Equal(edmType, result.Definition); Assert.IsAssignableFrom(expectedType, result); }