/// <summary> /// Resolves the expected EDM type full name to give to the ODataLib reader based on a client CLR type. /// </summary> /// <param name="clientClrType">The client side CLR type.</param> /// <returns>The resolved EDM type full name to provide to ODataLib.</returns> internal string ResolveServiceEntityTypeFullName(Type clientClrType) { Debug.Assert(clientClrType != null, "materializerType != null"); IEdmType edmType = this.ResolveExpectedTypeForReading(clientClrType); return(edmType != null?edmType.FullName() : null); }
/// <summary> /// ODL callback for client type resolution /// </summary> /// <param name="expectedEdmType">The expected type for the given wire name</param> /// <param name="wireName">The name of the type from the payload</param> /// <returns>An IEdmType</returns> internal IEdmType ResolveWireTypeName(IEdmType expectedEdmType, string wireName) { // ODataLib should never pass an empty or null type name Debug.Assert(!String.IsNullOrEmpty(wireName), "!String.IsNullOrEmpty(wireName)"); // For V3 and above, ODataLib will never call the type resolver if there is a collection // type specified in the wire. However, in V1/V2, since there was no collection feature // supported, it will call us with a collection wire name, but its okay to return null // in that case, since there is no collection supported. If the user writes the type // resolver in such a way to handle collections themselves, even then it will fail later // in ODataLib stating collection types are not supported in V1/V2 versions. if (expectedEdmType != null) { // In V1/V2, we never used to call the type resolver for primitives types. // Instead, we just used to look at the expected property type and try to convert // the value from the payload to the expected property type. In other words, we // used to ignore the type name on the wire for primitive properties. if (expectedEdmType.TypeKind == EdmTypeKind.Primitive) { return(expectedEdmType); } } Type expectedType; if (expectedEdmType != null) { ClientTypeAnnotation expectedAnnotation = this.clientEdmModel.GetClientTypeAnnotation(expectedEdmType); Debug.Assert(expectedAnnotation != null, "expectedAnnotation != null"); expectedType = expectedAnnotation.ElementType; } else { expectedType = typeof(object); } // Breaking change: we decided to validate against the resolved type if the type are not assignable. Type resolvedType = this.ResolveTypeFromName(wireName, expectedType); ClientTypeAnnotation resolvedTypeAnnotation = this.clientEdmModel.GetClientTypeAnnotation(this.clientEdmModel.GetOrCreateEdmType(resolvedType)); Debug.Assert(resolvedTypeAnnotation != null, "result != null -- otherwise ClientType.Create returned null"); IEdmType clientEdmType = resolvedTypeAnnotation.EdmType; EdmTypeKind typeKind = clientEdmType.TypeKind; if (typeKind == EdmTypeKind.Entity || typeKind == EdmTypeKind.Complex) { // If the edm type name is not present in the dictionary, add it to the map string edmTypeName = clientEdmType.FullName(); if (!this.edmTypeNameMap.ContainsKey(edmTypeName)) { this.edmTypeNameMap.Add(edmTypeName, resolvedTypeAnnotation); } } return(clientEdmType); }