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; }
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); } } }
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); }
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); } }