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 TInterface TryCreateRef <TInterface>(this IObjectRef objectRef) where TInterface : class, IObjectRef { TInterface local; if (!objectRef.TryCreateRef <TInterface>(out local).GetValueOrDefault()) { return(default(TInterface)); } return(local); }
public static bool?TryCreateRef <TInterface>(this IObjectRef objectRef, out TInterface newObjectRefT) where TInterface : class, IObjectRef { IObjectRef ref2; Validate.IsNotNull <IObjectRef>(objectRef, "objectRef"); bool?nullable = objectRef.TryCreateRef(typeof(TInterface), out ref2); if (!nullable.GetValueOrDefault()) { newObjectRefT = default(TInterface); return(nullable); } newObjectRefT = (TInterface)ref2; return(true); }
public static IObjectRef CreateRef(this IObjectRef objectRef, Type interfaceType) { IObjectRef ref2; bool? nullable = objectRef.TryCreateRef(interfaceType, out ref2); if (!nullable.HasValue) { throw new ObjectDisposedException(objectRef.GetType().FullName); } if (!nullable.Value) { throw new InterfaceNotSupportedException(interfaceType); } return(ref2); }
public static CastOrRefHolder <T> TryCastOrCreateRef <T>(this IObjectRef objectRef) where T : class, IObjectRef { T objectRefT = objectRef as T; if (objectRefT != null) { return(new CastOrRefHolder <T>(objectRefT, false)); } T local2 = objectRef.TryCreateRef <T>(); if (local2 != null) { return(new CastOrRefHolder <T>(local2, true)); } return(new CastOrRefHolder <T>()); }
public static UnsafeObjectRef?TryCreate(IObjectRef objectRef) { IObjectRef ref2; Validate.IsNotNull <IObjectRef>(objectRef, "objectRef"); RefTrackedObject obj2 = objectRef as RefTrackedObject; if (obj2 != null) { return(TryCreate(obj2)); } if (objectRef.TryCreateRef(typeof(IObjectRef), out ref2).GetValueOrDefault()) { return(new UnsafeObjectRef(ref2)); } return(null); }
public bool?TryGetAttachedObjectRef(object key, Type interfaceType, out IObjectRef newObjectRef) { Validate.IsNotNull <object>(key, "key"); IObjectRef ref2 = null; object sync = this.Sync; lock (sync) { if (this.attachedObjectRefs == null) { newObjectRef = null; return(false); } List <KeyValuePair <object, IObjectRef> > attachedObjectRefs = this.attachedObjectRefs as List <KeyValuePair <object, IObjectRef> >; if (attachedObjectRefs != null) { foreach (KeyValuePair <object, IObjectRef> pair in attachedObjectRefs) { if (pair.Key.Equals(key)) { ref2 = pair.Value; goto Label_00BB; } } } else { KeyValuePair <object, IObjectRef> pair2 = (KeyValuePair <object, IObjectRef>) this.attachedObjectRefs; if (pair2.Key.Equals(key)) { ref2 = pair2.Value; } } } Label_00BB: if (ref2 != null) { return(ref2.TryCreateRef(interfaceType, out newObjectRef).GetValueOrDefault()); } newObjectRef = null; return(false); }