System.Xml.Serialization.XmlSerializationReader.ShrinkArray C# (CSharp) Method

ShrinkArray() protected method

protected ShrinkArray ( Array a, int length, Type elementType, bool isNullable ) : Array
a Array
length int
elementType Type
isNullable bool
return Array
        protected Array ShrinkArray(Array a, int length, Type elementType, bool isNullable)
        {
            if (a == null)
            {
                if (isNullable) return null;
                return Array.CreateInstance(elementType, 0);
            }
            if (a.Length == length) return a;
            Array b = Array.CreateInstance(elementType, length);
            Array.Copy(a, b, length);
            return b;
        }
        // This is copied from Core's XmlReader.ReadString, as it is not exposed in the Contract.