コード例 #1
0
        /// <summary>
        /// Modified from http://codedmi.xyz/questions/421376/get-the-appdomain-of-object
        /// </summary>
        /// <param name="proxy"></param>
        /// <returns></returns>
        public static int GetObjectAppDomainId(object proxy)
        {
            int domainId = 0;

            RealProxy rp = RemotingServices.GetRealProxy(proxy);

            if (rp == null)
            {
                domainId = AppDomain.CurrentDomain.Id;
            }
            else
            {
                domainId = (int)rp.GetType().GetField("_domainID", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(rp);
            }

            return(domainId);
        }
コード例 #2
0
        public void GetRealProxy()
        {
            TcpChannel chn = null;

            try
            {
                chn = new TcpChannel(1241);
                ChannelServices.RegisterChannel(chn);

                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);

                MyProxy       proxy  = new  MyProxy(typeof(MarshalObject), (MarshalByRefObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1241/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));
                MarshalObject objRem = (MarshalObject)proxy.GetTransparentProxy();

                RealProxy rp = RemotingServices.GetRealProxy(objRem);

                Assert.IsTrue(rp != null, "#A12");
                Assert.AreEqual("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType().ToString(), "#A13");
            }
            finally
            {
                if (chn != null)
                {
                    ChannelServices.UnregisterChannel(chn);
                }
            }
        }
コード例 #3
0
        public void GetRealProxy()
        {
            var        port = NetworkHelpers.FindFreePort();
            TcpChannel chn  = new TcpChannel(port);

            ChannelServices.RegisterChannel(chn);
            try {
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);

                MyProxy       proxy  = new MyProxy(typeof(MarshalObject), (MarshalByRefObject)Activator.GetObject(typeof(MarshalObject), $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));
                MarshalObject objRem = (MarshalObject)proxy.GetTransparentProxy();

                RealProxy rp = RemotingServices.GetRealProxy(objRem);

                Assert.IsNotNull(rp, "#A12");
                Assert.AreEqual("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType().ToString(), "#A13");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }