private void InitSiWrite()
{
SerializationInfoEnumerator siEnum = null;
_isSi = true;
siEnum = _si.GetEnumerator();
int infoLength = 0;
infoLength = _si.MemberCount;
int count = infoLength;
// For ISerializable cache cannot be saved because each object instance can have different values
// BinaryWriter only puts the map on the wire if the ISerializable map cannot be reused.
TypeInformation typeInformation = null;
string fullTypeName = _si.FullTypeName;
string assemblyString = _si.AssemblyName;
bool hasTypeForwardedFrom = false;
if (!_si.IsFullTypeNameSetExplicit)
{
typeInformation = BinaryFormatter.GetTypeInformation(_si.ObjectType);
fullTypeName = typeInformation.FullTypeName;
hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
}
if (!_si.IsAssemblyNameSetExplicit)
{
if (typeInformation == null)
{
typeInformation = BinaryFormatter.GetTypeInformation(_si.ObjectType);
}
assemblyString = typeInformation.AssemblyString;
hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom;
}
_cache = new SerObjectInfoCache(fullTypeName, assemblyString, hasTypeForwardedFrom);
_cache._memberNames = new string[count];
_cache._memberTypes = new Type[count];
_memberData = new object[count];
siEnum = _si.GetEnumerator();
for (int i = 0; siEnum.MoveNext(); i++)
{
_cache._memberNames[i] = siEnum.Name;
_cache._memberTypes[i] = siEnum.ObjectType;
_memberData[i] = siEnum.Value;
}
_isNamed = true;
}