public void Serialize(BufferWriter writer, SharedContainer <T> instance, SerializationContext context) { // only serialize the resource. // The refCount needs not be serialized (it will be always 1 when deserializing) // The shared pool cannot be serialized, and needs to be provided by the deserializer, by providing a deserializing target that is already pool-aware this.handler.Serialize(writer, instance.resource, context); }
public void PrepareCloningTarget(SharedContainer <T> instance, ref SharedContainer <T> target, SerializationContext context) { if (target != null) { target.Release(); } target = instance; // needs to be set to the final object so that single-instancing works correctly }
public void PrepareDeserializationTarget(BufferReader reader, ref SharedContainer <T> target, SerializationContext context) { SharedPool <T> sharedPool = null; T resource = default(T); if (target != null) { target.Release(); sharedPool = target.SharedPool; sharedPool?.TryGet(out resource); } target = new SharedContainer <T>(resource, sharedPool); }
public void Clear(ref SharedContainer <T> target, SerializationContext context) { // shared containers cannot be reused throw new InvalidOperationException(); }
public void Deserialize(BufferReader reader, ref SharedContainer <T> target, SerializationContext context) { this.handler.Deserialize(reader, ref target.resource, context); }
public void Clone(SharedContainer <T> instance, ref SharedContainer <T> target, SerializationContext context) { target.AddRef(); }