Why C# Arrays type IsSerializable property is True?
Arrays
does not have anySerializable
attribute and also they aren't implementISerializable
interface
Array
class, an implicit base class of C# arrays, has [SerializableAttribute]
:
[SerializableAttribute][ComVisibleAttribute(true)]public abstract class Array : ICloneable, IList, ICollection, IEnumerable, IStructuralComparable, IStructuralEquatable
It also appears that the compiler adds [SerializableAttribute]
to the array type itself
foreach (var a in typeof(string[]).GetCustomAttributes(false)) { Console.WriteLine(a); // Prints "System.SerializableAttribute"}
Passing false
to GetCustomAttributes
ensures that only attributes for this class, and not for its base classes, are returned.