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; }
public static void AddCleanupRef(this ICleanupContainer container, IObjectRef objectRef) { container.AddCleanupObject(objectRef.CreateRef()); }