private void OnDeserialized(StreamingContext context) { // We only need to complete deserialization if we were hooking the deserialization process. If // we have not deserialized an object in the GetRealObject call, then there's nothing more for // us to do here. if (m_realObject != null) { // Fire the real object's OnDeserialized method if they registered one. Since we replaced // ourselves as the target of the deserialization, OnDeserialized on the target won't // automatically get triggered unless we do it manually. SerializationEvents cache = SerializationEventsCache.GetSerializationEventsForType(m_realObject.GetType()); cache.InvokeOnDeserialized(m_realObject, context); m_realObject = null; } }
internal static SerializationEvents GetSerializationEventsForType(Type t) { SerializationEvents events; if ((events = (SerializationEvents)cache[t]) == null) { lock (cache.SyncRoot) { if ((events = (SerializationEvents)cache[t]) == null) { events = new SerializationEvents(t); cache[t] = events; // Add this to the cache. } } } return(events); }
// [System.Security.SecurityCritical] // auto-generated_required public void RegisterObject(Object obj) { // Invoke OnSerializing for this object SerializationEvents cache = SerializationEventsCache.GetSerializationEventsForType(obj.GetType()); // Check to make sure type has serializing events if (cache.HasOnSerializingEvents) { // Check to see if we have invoked the events on the object if (m_objectSeenTable[obj] == null) { m_objectSeenTable[obj] = true; // Invoke the events cache.InvokeOnSerializing(obj, m_context); // Register for OnSerialized event AddOnSerialized(obj); } } }
private void AddOnSerialized(Object obj) { SerializationEvents cache = SerializationEventsCache.GetSerializationEventsForType(obj.GetType()); m_onSerializedHandler = cache.AddOnSerialized(obj, m_onSerializedHandler); }