public void NotifyType(string classNameInFile, Type t) { if (classNameInFile == "") { // must autodetect name classNameInFile = t.Name; int dot = classNameInFile.IndexOf('.'); // now remove any namespace stuff to leave just the final type if (dot > -1) { classNameInFile = classNameInFile.Substring(dot + 1, classNameInFile.Length - dot - 1); } classNameInFile = "C" + classNameInFile; // because we don't have 'C' on the beginning of every type name } ArchiveClass create = new ArchiveClass { Name = classNameInFile, TypeObject = t, Schema = -1 }; m_HashClasses.Add(t, create); }
public void NotifyType(string classNameInFile, Type t) { if (classNameInFile == "") { // must autodetect name classNameInFile = t.Name; int nDot = classNameInFile.IndexOf('.'); // now remove any namespace stuff to leave just the final type if (nDot > -1) { classNameInFile = classNameInFile.Substring(nDot + 1, classNameInFile.Length - nDot - 1); } classNameInFile = "C" + classNameInFile; // because we don't have 'C' on the beginning of every type name } Debug.Assert(typeof(IArchivable).IsAssignableFrom(t)); // check t is derived from IArchivable ArchiveClass a = new ArchiveClass { Name = classNameInFile, TypeObject = t }; m_HashClasses.Add(classNameInFile, a); }
public void Write(IArchivable o) { int existingIndex = m_WrittenObjects.IndexOf(o); if (existingIndex >= 0) { WriteTag((uint)existingIndex, false); } else { // object not get written - check if class name has been written if (!m_HashClasses.ContainsKey(o.GetType())) { throw new InvalidOperationException("Unexpected class type in ArchiveWriter" + o.GetType().ToString()); } ArchiveClass archiveClass = (ArchiveClass)m_HashClasses[o.GetType()]; if (archiveClass.Schema == -1) { // not yet written this class WriteTag(NewClassTag, true); WriteTag(0, false); //WriteTag(_nNextSchema, false); archiveClass.Schema = (int)m_NextIndex; m_NextIndex++; // for some reason name is not written as a length+string - instead it is always a 16-bit length followed by string data // (whereas normal StringL is 8-byte length unless that 8-bits indicates longer) base.Write(Convert.ToUInt16(archiveClass.Name.Length)); WriteStringBytes(archiveClass.Name); } else { WriteTag((uint)archiveClass.Schema, true); } m_NextIndex++; // object itself also counted in index m_WrittenObjects.Add(o); o.Write(this); } }