internal static Context GetServerContext(MarshalByRefObject obj)
{
Context serverCtx = null;
if(!IsTransparentProxy(obj) && (obj is ContextBoundObject))
{
// The object is native to the current context.
serverCtx = Thread.CurrentContext;
}
else
{
RealProxy rp = GetRealProxy(obj);
Identity id = rp.IdentityObject;
ServerIdentity serverID = id as ServerIdentity;
if(null != serverID)
{
// The object was born in the current appdomain.
// Extract the server context.
serverCtx = serverID.ServerContext;
}
}
return serverCtx;
}