private static IObjectRef GetRef(IObjectRef objectRef, Type interfaceType, bool addRef) { if (!addRef) { return(objectRef); } return(objectRef.CreateRef(interfaceType)); }
public static TInterface CreateRef <TInterface>(this IObjectRef objectRef) where TInterface : class, IObjectRef => ((TInterface)objectRef.CreateRef(typeof(TInterface)));
public bool TryAttachObjectRef(object key, IObjectRef objectRef) { bool flag3; Validate.Begin().IsNotNull <object>(key, "key").IsNotNull <IObjectRef>(objectRef, "objectRef").Check(); if ((key is KeyValuePair <object, IObjectRef>) || (key is List <KeyValuePair <object, IObjectRef> >)) { ExceptionUtil.ThrowArgumentException($"{key.GetType().Name} is a disallowed key type"); } IObjectRef ref2 = objectRef.CreateRef(); bool flag = false; KeyValuePair <object, IObjectRef> item = new KeyValuePair <object, IObjectRef>(key, ref2); try { object sync = this.Sync; lock (sync) { if (this.attachedObjectRefs == null) { this.attachedObjectRefs = item; return(true); } List <KeyValuePair <object, IObjectRef> > attachedObjectRefs = this.attachedObjectRefs as List <KeyValuePair <object, IObjectRef> >; if (attachedObjectRefs != null) { foreach (KeyValuePair <object, IObjectRef> pair2 in attachedObjectRefs) { if (pair2.Key.Equals(key)) { flag = true; return(false); } } attachedObjectRefs.Add(item); return(true); } KeyValuePair <object, IObjectRef> pair3 = (KeyValuePair <object, IObjectRef>) this.attachedObjectRefs; if (pair3.Key.Equals(key)) { flag = true; return(false); } List <KeyValuePair <object, IObjectRef> > list2 = new List <KeyValuePair <object, IObjectRef> >(2) { pair3, item }; this.attachedObjectRefs = list2; flag3 = true; } } finally { if (flag) { ref2.Dispose(); } } return(flag3); }
public static IObjectRef CreateRef(this IObjectRef objectRef) => objectRef.CreateRef(typeof(IObjectRef));
public static void AddCleanupRef(this ICleanupContainer container, IObjectRef objectRef) { container.AddCleanupObject(objectRef.CreateRef()); }