Created
September 18, 2013 14:09
-
-
Save tvolodimir/6609668 to your computer and use it in GitHub Desktop.
CreateProxy Instance in AppDomain
This file contains 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
public sealed class Remote<T> where T : MarshalByRefObject | |
{ | |
private readonly AppDomain domain; | |
private readonly T remoteObject; | |
private Remote(AppDomain domain, T remoteObject) | |
{ | |
this.domain = domain; | |
this.remoteObject = remoteObject; | |
} | |
public T RemoteObject | |
{ | |
get { return remoteObject; } | |
} | |
public AppDomain Domain | |
{ | |
get { return domain; } | |
} | |
public static Remote<T> CreateProxy(AppDomain domain, params object[] constructorArgs) | |
{ | |
if (domain == null) | |
{ | |
throw new ArgumentNullException("domain"); | |
} | |
var type = typeof(T); | |
var proxy = (T)domain.CreateInstanceAndUnwrap( | |
type.Assembly.FullName, | |
type.FullName, | |
false, | |
BindingFlags.CreateInstance, | |
null, | |
constructorArgs, | |
null, | |
null); | |
return new Remote<T>(domain, proxy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment