public void Write(object instance, INodeWriter parentNode, Type referencedAsType) { var objectID = valuesCache.Add(instance); var typeName = typeNamesCache.GetTypeName(instance.GetType()); using (var classNode = ownerDocument.CreateClassElement(typeName, objectID, parentNode)) { using (var membersNode = ownerDocument.CreateMembersElement(classNode)) { memberWriter.Write(instance, membersNode, instance.GetType()); } baseTypeMembersWriter.WriteMembers(instance, classNode, instance.GetType()); } }