/// <summary> /// Tries to convert the given value if it is of a type specific to the client library but still able to be mapped to EDM. /// </summary> /// <param name="primitiveValue">The value to convert.</param> /// <param name="type">The expected type of the value or null.</param> /// <param name="convertedValue">The converted value, if conversion was possible.</param> /// <returns>Whether or not conversion was possible.</returns> private static bool TryConvertClientSpecificPrimitiveValue(object primitiveValue, IEdmPrimitiveTypeReference type, out IEdmDelayedValue convertedValue) { byte[] byteArray; if (ClientConvert.TryConvertBinaryToByteArray(primitiveValue, out byteArray)) { type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Binary); convertedValue = new EdmBinaryConstant((IEdmBinaryTypeReference)type, byteArray); return(true); } PrimitiveType clientPrimitiveType; if (PrimitiveType.TryGetPrimitiveType(primitiveValue.GetType(), out clientPrimitiveType)) { type = EnsurePrimitiveType(type, clientPrimitiveType.PrimitiveKind); if (clientPrimitiveType.PrimitiveKind == EdmPrimitiveTypeKind.String) { { convertedValue = new EdmStringConstant((IEdmStringTypeReference)type, clientPrimitiveType.TypeConverter.ToString(primitiveValue)); return(true); } } } convertedValue = null; return(false); }
private static bool TryGetByteArrayFromBinary(object value, out byte[] array) { // DEVNOTE: the client does not have a reference to System.Data.Linq, but the server does. // So we need to interact with Binary differently. #if ASTORIA_SERVER Binary binary = value as Binary; if (binary != null) { array = binary.ToArray(); return(true); } #endif #if ASTORIA_CLIENT return(ClientConvert.TryConvertBinaryToByteArray(value, out array)); #else array = null; return(false); #endif }