Skip to content
Viktor Elofsson edited this page Jul 11, 2014 · 3 revisions

The dynamic proxy lets you work with a jailed class instance without any type knowledge. Function calls (including properties) will be forwarded to the target instance along with any arguments.

Example

Our jailed class

using System;

namespace Unknown
{
    public class Foo
    {
        public int Times { get; set; }

        public void Say(string message)
        {
            for(var i = 0; i < Times; i++)
            {
                Console.WriteLine(message);
            }
        }
    }
}

Creating a dynamic proxy

The following code will create a dynamic proxy to the above class and call the Say function on it. Running this will write "Hello, Jails!" to the console ten times.

dynamic proxy = jail.Resolve("Unknown.Foo");
proxy.Times = 10;
proxy.Say("Hello, Jails!");
Clone this wiki locally