// This is the main routine you should call from your Freeze // callbacks to freeze an object public void ObjRef(object o) { int id; SerUnit altunit; if (Config.SerTrace) { Console.WriteLine("Saving {0} at {1}...", o, wpointer); } if (o == null) // null pointers are special { Byte((byte)SerializationCode.Null); return; } if (reg.CheckWriteObject(unit, o, out altunit, out id)) { if (altunit == unit) { Byte((byte)SerializationCode.SelfRef); } else { int altcode; if (!unit_to_offset.TryGetValue(altunit, out altcode)) { Byte((byte)SerializationCode.NewUnitRef); String(altunit.name); // save the hash too so stale refs can be caught foreach (byte b in altunit.hash) { Byte(b); } unit_to_offset[altunit] = usedunits++; } else { Byte((byte)SerializationCode.ForeignRef); Int(altcode); } } Int((int)id); } else { // must take responsibility for saving the tag IFreeze f = o as IFreeze; if (f != null) { f.Freeze(this); } else { FallbackFreeze(o); } } }