Created
February 26, 2013 19:14
-
-
Save kumpera/5041190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using NUnit.Framework; | |
| using System.Runtime.Remoting; | |
| using System.Runtime.Remoting.Channels; | |
| using System.Runtime.Remoting.Proxies; | |
| using System.Runtime.Remoting.Messaging; | |
| namespace remoting | |
| { | |
| public class MyProxy : RealProxy { | |
| MarshalByRefObject obj; | |
| string uri; | |
| public MyProxy(Type myType) : base(myType) | |
| { | |
| obj = (MarshalByRefObject)Activator.CreateInstance((myType)); | |
| var oref = RemotingServices.Marshal(obj); | |
| uri = oref.URI; | |
| Console.WriteLine ("URI is {0}", uri); | |
| } | |
| public override IMessage Invoke (IMessage msg) | |
| { | |
| Console.WriteLine ("Invoke {0}", msg); | |
| msg.Properties ["__Uri"] = uri; | |
| return ChannelServices.SyncDispatchMessage (msg); | |
| } | |
| } | |
| class Foo : MarshalByRefObject | |
| { | |
| public string Bar () { return "real"; } | |
| } | |
| [TestFixture] | |
| public class TransparentProxyTest | |
| { | |
| [Test] | |
| public void Pass () | |
| { | |
| var rp = new MyProxy (typeof (Foo)); | |
| var foo = (Foo)rp.GetTransparentProxy (); | |
| Assert.AreEqual ("real", foo.Bar ()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment