-
Notifications
You must be signed in to change notification settings - Fork 2
Dynamic proxy
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.
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);
}
}
}
}
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!");