/// <summary> /// Creates a new event instance based on the specified type identifier. /// </summary> public Event CreateEvent(int typeId) { // Try link-local event factory first. Event result = EventFactory.Create(typeId); if (!ReferenceEquals(result, null)) { return(result); } // If not fount, try the global event factory. return(EventFactory.Global.Create(typeId)); }
/// <summary> /// Decodes a Cell-derived objects out of the underlying buffer. /// </summary> public void Read <T>(out T value) where T : Cell, new() { value = null; int length; ReadNonnegative(out length); if (length == 0) { return; } int marker = buffer.Position + length; Type type = typeof(T); Type eventType = typeof(Event); if (type.IsSubclassOf(eventType) || type == eventType) { int typeId; Read(out typeId); Event e = null; if (!ReferenceEquals(eventFactory, null)) { e = eventFactory.Create(typeId); } if (ReferenceEquals(e, null)) { e = EventFactory.Global.Create(typeId); } if (ReferenceEquals(e, null)) { Trace.Error("error deserializing {0}: unknown event type id {1}", type.Name, typeId); } value = (T)((Cell)e); } else { value = new T(); } if (!ReferenceEquals(value, null)) { value.Deserialize(this); } if (buffer.Position != marker) { buffer.Position = marker; } }