private static void SerializeGraph(BinaryWriter writer, Encoding encoding, Type graphType, SerializationInfo graph) {
var fullName = graphType.AssemblyQualifiedName;
if (String.IsNullOrEmpty(fullName))
throw new InvalidOperationException("Could not obtain the assembly qualified name of the type.");
writer.Write(fullName);
var count = graph.MemberCount;
writer.Write(count);
var en = graph.GetEnumerator();
while (en.MoveNext()) {
var key = en.Name;
var keyLength = key.Length;
writer.Write(keyLength);
writer.Write(key.ToCharArray());
var value = en.Value;
var objType = en.ObjectType;
#if PCL
if (objType.IsAbstract() && value != null)
#else
if ((objType.IsAbstract ||
objType.IsInterface) &&
value != null)
#endif
objType = value.GetType();
SerializeValue(writer, encoding, objType, value);
}
}