/// <summary> /// Returns <c>true</c> if the given type is either primitive or one of our /// standard acceptable simple types, such as <see cref="String"/>, /// <see cref="Guid"/>, etc /// </summary> /// <param name="type">The type to test</param> /// <returns><c>true</c> if the type is a primitive or standard acceptable types</returns> public static bool IsPredefinedSimpleType(Type type) { type = GetNonNullableType(type); // primitive types (except IntPtr and UIntPtr) are supported if (type.IsPrimitive && type != typeof(IntPtr) && type != typeof(UIntPtr)) { return(true); } if (type.IsEnum) { return(true); } if (predefinedTypes.Contains(type)) { return(true); } if (BinaryTypeUtility.IsTypeBinary(type)) { return(true); } // We test XElement by Type Name so our client framework assembly can avoid // taking an assembly reference to System.Xml.Linq if (string.Compare(type.FullName, "System.Xml.Linq.XElement", StringComparison.Ordinal) == 0) { return(true); } return(false); }
/// <summary> /// Gets the type that should be used on the client for the specified type. /// </summary> /// <param name="t">The type to get the client type for.</param> /// <returns>The client type.</returns> public static Type GetClientType(Type t) { if (BinaryTypeUtility.IsTypeBinary(t)) { return(typeof(byte[])); } return(t); }
/// <summary> /// Gets a value that can be used by the client. /// </summary> /// <remarks> /// This method should be kept in sync with DataContractSurrogateGenerator.EmitToClientConversion. /// </remarks> /// <param name="targetType">The type used by the client.</param> /// <param name="value">The value on the server.</param> /// <returns>A value that can be used by the client.</returns> public static object GetClientValue(Type targetType, object value) { if (value == null) { return(null); } if (targetType == typeof(byte[]) && BinaryTypeUtility.IsTypeBinary(value.GetType())) { return(BinaryTypeUtility.GetByteArrayFromBinary(value)); } return(value); }
/// <summary> /// Gets a value that can be used by the server. /// </summary> /// <remarks> /// This method should be kept in sync with DataContractSurrogateGenerator.EmitToServerConversion. /// </remarks> /// <param name="targetType">The type used by the server.</param> /// <param name="value">The value from the client.</param> /// <returns>A value that can be used by the server.</returns> public static object GetServerValue(Type targetType, object value) { if (value == null) { return(null); } byte[] valueAsByteArray = value as byte[]; if (BinaryTypeUtility.IsTypeBinary(targetType) && (valueAsByteArray != null)) { return(BinaryTypeUtility.GetBinaryFromByteArray(valueAsByteArray)); } return(value); }