internal static object ConvertValue( object odataValue, string parameterName, Type expectedReturnType, IEdmTypeReference propertyType, IEdmModel model, HttpRequestMessage request, IServiceProvider serviceProvider) { var readContext = new ODataDeserializerContext { Model = model, Request = request }; var returnValue = ODataModelBinderConverter.Convert( odataValue, propertyType, expectedReturnType, parameterName, readContext, serviceProvider); if (!propertyType.IsCollection()) { return(returnValue); } return(ConvertCollectionType(returnValue, expectedReturnType)); }
public void Convert_CheckPrimitives(object odataValue, EdmPrimitiveTypeKind edmTypeKind, Type clrType, object expectedResult) { var edmTypeReference = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(edmTypeKind), false); var value = new ConstantNode(odataValue, odataValue.ToString(), edmTypeReference); var result = ODataModelBinderConverter.Convert(value, edmTypeReference, clrType, "IsActive", null, null); Assert.NotNull(result); Assert.IsType(clrType, result); Assert.Equal(expectedResult, result); }
public void Convert_CheckTypeDefinitionPrimitives(object odataValue, EdmPrimitiveTypeKind edmTypeKind, Type clrType, object expectedResult) { var edmTypeDefinition = new EdmTypeDefinition(clrType.Namespace, clrType.Name, edmTypeKind); var edmTypeDefReference = new EdmTypeDefinitionReference(edmTypeDefinition, false); var result = ODataModelBinderConverter.Convert(odataValue, edmTypeDefReference, clrType, "IsActive", null, null); Assert.NotNull(result); Assert.IsType(clrType, result); Assert.Equal(expectedResult, result); }
internal static object ConvertValue( object odataValue, string parameterName, Type expectedReturnType, IEdmTypeReference propertyType, IEdmModel model, HttpRequestMessage request, IServiceProvider serviceProvider) { var readContext = new ODataDeserializerContext { Model = model, Request = request }; // IS 2020-09-01 // primitive value if (propertyType.IsPrimitive()) { if (odataValue is OData.UriParser.ConstantNode) { OData.UriParser.ConstantNode node = odataValue as OData.UriParser.ConstantNode; return(node.Value); } //return EdmPrimitiveHelpers.ConvertPrimitiveValue(node != null ? node.Value : graph, clrType); } // IS 2020-09-01 var returnValue = ODataModelBinderConverter.Convert(odataValue, propertyType, expectedReturnType, parameterName, readContext, serviceProvider); if (!propertyType.IsCollection()) { return(returnValue); } return(ConvertCollectionType(returnValue, expectedReturnType)); }