/// <summary>
        /// Create a proxy for the given object (and record the mapping)
        /// </summary>
        /// <param name="obj">Object.</param>
        public static int ProxyIdFor(object obj)
        {
            var iproxy = obj as CLRObjectProxy;

            if (iproxy != null)
            {
                return(iproxy.ObjectId);
            }

            int objectid = 0;

            if (_cache_oi.TryGetValue(obj, out objectid))
            {
                return(objectid);
            }

            var proxy = new CLRObjectProxy(Interlocked.Increment(ref _idgenerator));

            _cache_io [proxy.ObjectId] = obj;
            _cache_oi [obj]            = proxy.ObjectId;
            return(proxy.ObjectId);
        }
 /// <summary>
 /// Release the specified proxy.
 /// </summary>
 /// <param name="proxy">Proxy.</param>
 public static void Release(CLRObjectProxy proxy)
 {
     Release(proxy.ObjectId);
 }
 /// <summary>
 /// Find object by proxy
 /// </summary>
 /// <param name="proxy">Proxy.</param>
 /// <param name="obj">Mapped object.</param>
 public static bool TryFindObject(CLRObjectProxy proxy, out object obj)
 {
     return(_cache_io.TryGetValue(proxy.ObjectId, out obj));
 }
Exemple #4
0
 /// <summary>
 /// Releases object for GCing
 /// </summary>
 /// <param name="req">Request.</param>
 private void HandleRelease(CLRReleaseMessage req)
 {
     CLRObjectProxy.Release(req.ObjectId);
 }