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.