/// <summary> /// The validation check on whether a type is serializable /// </summary> /// <param name="type">The type to test</param> /// <returns>Returns whether that type can be serialized</returns> public static bool TypeIsSerializable(Type type) { if (type == null) { throw new ArgumentNullException("type"); } if (!type.IsSerializable) { return(false); } if (!type.IsGenericType) { return(true); } Type[] genericArguments = type.GetGenericArguments(); for (int i = 0; i < genericArguments.Length; i++) { Type type2 = genericArguments[i]; if (!SerializationTypeConverter.TypeIsSerializable(type2)) { return(false); } } return(true); }
/// <summary> /// Whether a type can be serialized /// </summary> /// <param name="type">The type to test</param> /// <returns>Whether the specified type can be serialized</returns> public static bool CanSerialize(Type type) { return(SerializationTypeConverter.TypeIsSerializable(type) && !type.IsEnum || (type.Equals(typeof(Exception)) || type.IsSubclassOf(typeof(Exception)))); }