Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
            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
            }
Exemplo n.º 3
0
            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);
            }
Exemplo n.º 4
0
 public void Clear(ref SharedContainer <T> target, SerializationContext context)
 {
     // shared containers cannot be reused
     throw new InvalidOperationException();
 }
Exemplo n.º 5
0
 public void Deserialize(BufferReader reader, ref SharedContainer <T> target, SerializationContext context)
 {
     this.handler.Deserialize(reader, ref target.resource, context);
 }
Exemplo n.º 6
0
 public void Clone(SharedContainer <T> instance, ref SharedContainer <T> target, SerializationContext context)
 {
     target.AddRef();
 }