示例#1
0
 public bool? TryCreateRef(Type interfaceType, out IObjectRef newObjectRef)
 {
     RefTrackedObject cleanupContainer;
     Validate.IsNotNull<Type>(interfaceType, "interfaceType");
     IObjectRef innerRef = this.innerRef;
     if (innerRef == null)
     {
         newObjectRef = null;
         return null;
     }
     bool? nullable = innerRef.TryCreateRef(interfaceType, out newObjectRef);
     if (!nullable.GetValueOrDefault())
     {
         return null;
     }
     ObjectRefProxy proxy = this;
     lock (proxy)
     {
         this.EnsureCleanupContainerCreatedWhileLocked();
         cleanupContainer = this.cleanupContainer;
     }
     ICleanupContainer container = newObjectRef as ICleanupContainer;
     if (container == null)
     {
         ObjectRefProxy proxy2 = Create(interfaceType, newObjectRef, ObjectRefProxyOptions.AssumeOwnership);
         proxy2.AddCleanupRef(cleanupContainer);
         newObjectRef = proxy2;
         return nullable;
     }
     container.AddCleanupRef(cleanupContainer);
     return nullable;
 }
示例#2
0
 private void DisposeCore(bool disposing)
 {
     if (Interlocked.Exchange(ref this.isDisposed, 1) == 0)
     {
         try
         {
             this.Dispose(disposing);
         }
         finally
         {
             IObjectRef innerRef = this.innerRef;
             this.InnerRef = null;
             if ((this.proxyOptions & ObjectRefProxyOptions.DoNotCreateRef) != ObjectRefProxyOptions.DoNotCreateRef)
             {
                 IRefTrackedObject obj2 = innerRef as IRefTrackedObject;
                 if (obj2 != null)
                 {
                     obj2.ReleaseRef(this, disposing);
                 }
             }
         }
         if (disposing)
         {
             RefTrackedObject cleanupContainer;
             ObjectRefProxy proxy = this;
             lock (proxy)
             {
                 cleanupContainer = this.cleanupContainer;
                 this.cleanupContainer = null;
             }
             DisposableUtil.Free<RefTrackedObject>(ref cleanupContainer, disposing);
         }
     }
 }
示例#3
0
 protected virtual IObjectRefProxy TryCreateProxy(Type interfaceType, ObjectRefProxyOptions proxyOptions)
 {
     if (!typeof(IObjectRefProxy).IsAssignableFrom(interfaceType) && interfaceType.IsAssignableFrom(base.GetType()))
     {
         return(ObjectRefProxy.Create(interfaceType, this, proxyOptions));
     }
     return(null);
 }
示例#4
0
 public void AddCleanupObject(IDisposable cleanupObject)
 {
     Validate.IsNotNull<IDisposable>(cleanupObject, "cleanupObject");
     if (this.innerRef.IsNullReference<IObjectRef>())
     {
         ExceptionUtil.ThrowObjectDisposedException(base.GetType().Name);
     }
     ObjectRefProxy proxy = this;
     lock (proxy)
     {
         this.EnsureCleanupContainerCreatedWhileLocked();
         this.cleanupContainer.AddCleanupObject(cleanupObject);
     }
 }