using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
namespace System.Runtime.Remoting.Proxies
{
/// Provides base functionality for proxies.
// Token: 0x02000433 RID: 1075
[ComVisible(true)]
public abstract class RealProxy
{
/// Initializes a new instance of the class with default values.
// Token: 0x06002982 RID: 10626 RVA: 0x0008554C File Offset: 0x0008374C
protected RealProxy()
{
}
/// Initializes a new instance of the class that represents a remote object of the specified .
/// The of the remote object for which to create a proxy.
///
/// is not an interface, and is not derived from .
// Token: 0x06002983 RID: 10627 RVA: 0x0008555C File Offset: 0x0008375C
protected RealProxy(Type classToProxy)
: this(classToProxy, IntPtr.Zero, null)
{
}
// Token: 0x06002984 RID: 10628 RVA: 0x0008556C File Offset: 0x0008376C
internal RealProxy(Type classToProxy, ClientIdentity identity)
: this(classToProxy, IntPtr.Zero, null)
{
this._objectIdentity = identity;
}
/// Initializes a new instance of the class.
/// The of the remote object for which to create a proxy.
/// A stub to associate with the new proxy instance.
/// The stub data to set for the specified stub and the new proxy instance.
///
/// is not an interface, and is not derived from .
// Token: 0x06002985 RID: 10629 RVA: 0x00085584 File Offset: 0x00083784
protected RealProxy(Type classToProxy, IntPtr stub, object stubData)
{
if (!classToProxy.IsMarshalByRef && !classToProxy.IsInterface)
{
throw new ArgumentException("object must be MarshalByRef");
}
this.class_to_proxy = classToProxy;
if (stub != IntPtr.Zero)
{
throw new NotSupportedException("stub is not used in Mono");
}
}
// Token: 0x06002986 RID: 10630
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Type InternalGetProxyType(object transparentProxy);
/// Returns the of the object that the current instance of represents.
/// The of the object that the current instance of represents.
///
///
///
// Token: 0x06002987 RID: 10631 RVA: 0x000855E4 File Offset: 0x000837E4
public Type GetProxiedType()
{
if (this._objTP != null)
{
return RealProxy.InternalGetProxyType(this._objTP);
}
if (this.class_to_proxy.IsInterface)
{
return typeof(MarshalByRefObject);
}
return this.class_to_proxy;
}
/// Creates an for the specified object type, and registers it with the remoting infrastructure as a client-activated object.
/// A new instance of that is created for the specified type.
/// The object type that an is created for.
///
///
///
// Token: 0x06002988 RID: 10632 RVA: 0x0008562C File Offset: 0x0008382C
public virtual ObjRef CreateObjRef(Type requestedType)
{
return RemotingServices.Marshal((MarshalByRefObject)this.GetTransparentProxy(), null, requestedType);
}
/// Adds the transparent proxy of the object represented by the current instance of to the specified .
/// The into which the transparent proxy is serialized.
/// The source and destination of the serialization.
/// The or parameter is null.
/// The immediate caller does not have SerializationFormatter permission.
///
///
///
///
// Token: 0x06002989 RID: 10633 RVA: 0x00085640 File Offset: 0x00083840
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
object transparentProxy = this.GetTransparentProxy();
RemotingServices.GetObjectData(transparentProxy, info, context);
}
// Token: 0x1700083D RID: 2109
// (get) Token: 0x0600298A RID: 10634 RVA: 0x0008565C File Offset: 0x0008385C
// (set) Token: 0x0600298B RID: 10635 RVA: 0x00085664 File Offset: 0x00083864
internal Identity ObjectIdentity
{
get
{
return this._objectIdentity;
}
set
{
this._objectIdentity = value;
}
}
/// Requests an unmanaged reference to the object represented by the current proxy instance.
/// A pointer to a COM Callable Wrapper if the object reference is requested for communication with unmanaged objects in the current process through COM, or a pointer to a cached or newly generated IUnknown COM interface if the object reference is requested for marshaling to a remote location.
/// true if the object reference is requested for marshaling to a remote location; false if the object reference is requested for communication with unmanaged objects in the current process through COM.
///
///
///
// Token: 0x0600298C RID: 10636 RVA: 0x00085670 File Offset: 0x00083870
[MonoTODO]
public virtual IntPtr GetCOMIUnknown(bool fIsMarshalled)
{
throw new NotImplementedException();
}
/// Stores an unmanaged proxy of the object that is represented by the current instance.
/// A pointer to the IUnknown interface for the object that is represented by the current proxy instance.
///
///
///
// Token: 0x0600298D RID: 10637 RVA: 0x00085678 File Offset: 0x00083878
[MonoTODO]
public virtual void SetCOMIUnknown(IntPtr i)
{
throw new NotImplementedException();
}
/// Requests a COM interface with the specified ID.
/// A pointer to the requested interface.
/// A reference to the requested interface.
///
///
///
// Token: 0x0600298E RID: 10638 RVA: 0x00085680 File Offset: 0x00083880
[MonoTODO]
public virtual IntPtr SupportsInterface(ref Guid iid)
{
throw new NotImplementedException();
}
/// Retrieves stub data that is stored for the specified proxy.
/// Stub data for the specified proxy.
/// The proxy for which stub data is requested.
/// The immediate caller does not have UnmanagedCode permission.
///
///
///
// Token: 0x0600298F RID: 10639 RVA: 0x00085688 File Offset: 0x00083888
public static object GetStubData(RealProxy rp)
{
return rp._stubData;
}
/// Sets the stub data for the specified proxy.
/// The proxy for which to set stub data.
/// The new stub data.
/// The immediate caller does not have UnmanagedCode permission.
///
///
///
// Token: 0x06002990 RID: 10640 RVA: 0x00085690 File Offset: 0x00083890
public static void SetStubData(RealProxy rp, object stubData)
{
rp._stubData = stubData;
}
/// When overridden in a derived class, invokes the method that is specified in the provided on the remote object that is represented by the current instance.
/// The message returned by the invoked method, containing the return value and any out or ref parameters.
/// A that contains a of information about the method call.
///
///
///
// Token: 0x06002991 RID: 10641
public abstract IMessage Invoke(IMessage msg);
// Token: 0x06002992 RID: 10642 RVA: 0x0008569C File Offset: 0x0008389C
internal static object PrivateInvoke(RealProxy rp, IMessage msg, out Exception exc, out object[] out_args)
{
MonoMethodMessage monoMethodMessage = (MonoMethodMessage)msg;
monoMethodMessage.LogicalCallContext = CallContext.CreateLogicalCallContext(true);
CallType callType = monoMethodMessage.CallType;
bool flag = rp is RemotingProxy;
out_args = null;
IMethodReturnMessage methodReturnMessage = null;
if (callType == CallType.BeginInvoke)
{
monoMethodMessage.AsyncResult.CallMessage = monoMethodMessage;
}
if (callType == CallType.EndInvoke)
{
methodReturnMessage = (IMethodReturnMessage)monoMethodMessage.AsyncResult.EndInvoke();
}
if (monoMethodMessage.MethodBase.IsConstructor)
{
if (flag)
{
methodReturnMessage = (IMethodReturnMessage)(rp as RemotingProxy).ActivateRemoteObject((IMethodMessage)msg);
}
else
{
msg = new ConstructionCall(rp.GetProxiedType());
}
}
if (methodReturnMessage == null)
{
bool flag2 = false;
try
{
methodReturnMessage = (IMethodReturnMessage)rp.Invoke(msg);
}
catch (Exception ex)
{
flag2 = true;
if (callType != CallType.BeginInvoke)
{
throw;
}
monoMethodMessage.AsyncResult.SyncProcessMessage(new ReturnMessage(ex, msg as IMethodCallMessage));
methodReturnMessage = new ReturnMessage(null, null, 0, null, msg as IMethodCallMessage);
}
if (!flag && callType == CallType.BeginInvoke && !flag2)
{
IMessage message = monoMethodMessage.AsyncResult.SyncProcessMessage(methodReturnMessage);
out_args = methodReturnMessage.OutArgs;
methodReturnMessage = new ReturnMessage(message, null, 0, null, methodReturnMessage as IMethodCallMessage);
}
}
if (methodReturnMessage.LogicalCallContext != null && methodReturnMessage.LogicalCallContext.HasInfo)
{
CallContext.UpdateCurrentCallContext(methodReturnMessage.LogicalCallContext);
}
exc = methodReturnMessage.Exception;
if (exc != null)
{
out_args = null;
throw exc.FixRemotingException();
}
if (methodReturnMessage is IConstructionReturnMessage)
{
if (out_args == null)
{
out_args = methodReturnMessage.OutArgs;
}
}
else if (monoMethodMessage.CallType != CallType.BeginInvoke)
{
if (monoMethodMessage.CallType == CallType.Sync)
{
out_args = RealProxy.ProcessResponse(methodReturnMessage, monoMethodMessage);
}
else if (monoMethodMessage.CallType == CallType.EndInvoke)
{
out_args = RealProxy.ProcessResponse(methodReturnMessage, monoMethodMessage.AsyncResult.CallMessage);
}
else if (out_args == null)
{
out_args = methodReturnMessage.OutArgs;
}
}
return methodReturnMessage.ReturnValue;
}
// Token: 0x06002993 RID: 10643
[MethodImpl(MethodImplOptions.InternalCall)]
internal virtual extern object InternalGetTransparentProxy(string className);
/// Returns the transparent proxy for the current instance of .
/// The transparent proxy for the current proxy instance.
///
///
///
// Token: 0x06002994 RID: 10644 RVA: 0x000858B4 File Offset: 0x00083AB4
public virtual object GetTransparentProxy()
{
if (this._objTP == null)
{
IRemotingTypeInfo remotingTypeInfo = this as IRemotingTypeInfo;
string text;
if (remotingTypeInfo != null)
{
text = remotingTypeInfo.TypeName;
if (text == null || text == typeof(MarshalByRefObject).AssemblyQualifiedName)
{
text = this.class_to_proxy.AssemblyQualifiedName;
}
}
else
{
text = this.class_to_proxy.AssemblyQualifiedName;
}
this._objTP = this.InternalGetTransparentProxy(text);
}
return this._objTP;
}
/// Initializes a new instance of the object of the remote object that the current instance of represents with the specified .
/// The result of the construction request.
/// A construction call message that contains the constructor parameters for the new instance of the remote object that is represented by the current . Can be null.
/// The immediate caller does not have UnmanagedCode permission.
///
///
///
///
// Token: 0x06002995 RID: 10645 RVA: 0x00085930 File Offset: 0x00083B30
[MonoTODO]
[ComVisible(true)]
public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg)
{
throw new NotImplementedException();
}
/// Attaches the current proxy instance to the specified remote .
/// The that the current proxy instance represents.
/// The immediate caller does not have UnmanagedCode permission.
// Token: 0x06002996 RID: 10646 RVA: 0x00085938 File Offset: 0x00083B38
protected void AttachServer(MarshalByRefObject s)
{
this._server = s;
}
/// Detaches the current proxy instance from the remote server object that it represents.
/// The detached server object.
/// The immediate caller does not have UnmanagedCode permission.
// Token: 0x06002997 RID: 10647 RVA: 0x00085944 File Offset: 0x00083B44
protected MarshalByRefObject DetachServer()
{
MarshalByRefObject server = this._server;
this._server = null;
return server;
}
/// Returns the server object that is represented by the current proxy instance.
/// The server object that is represented by the current proxy instance.
/// The immediate caller does not have UnmanagedCode permission.
// Token: 0x06002998 RID: 10648 RVA: 0x00085960 File Offset: 0x00083B60
protected MarshalByRefObject GetUnwrappedServer()
{
return this._server;
}
// Token: 0x06002999 RID: 10649 RVA: 0x00085968 File Offset: 0x00083B68
internal void SetTargetDomain(int domainId)
{
this._targetDomainId = domainId;
}
// Token: 0x0600299A RID: 10650 RVA: 0x00085974 File Offset: 0x00083B74
internal object GetAppDomainTarget()
{
if (this._server == null)
{
ClientActivatedIdentity clientActivatedIdentity = RemotingServices.GetIdentityForUri(this._targetUri) as ClientActivatedIdentity;
if (clientActivatedIdentity == null)
{
throw new RemotingException("Server for uri '" + this._targetUri + "' not found");
}
this._server = clientActivatedIdentity.GetServerObject();
}
return this._server;
}
// Token: 0x0600299B RID: 10651 RVA: 0x000859D0 File Offset: 0x00083BD0
private static object[] ProcessResponse(IMethodReturnMessage mrm, MonoMethodMessage call)
{
MethodInfo methodInfo = (MethodInfo)call.MethodBase;
if (mrm.ReturnValue != null && !methodInfo.ReturnType.IsInstanceOfType(mrm.ReturnValue))
{
throw new InvalidCastException("Return value has an invalid type");
}
int num;
if (call.NeedsOutProcessing(out num))
{
ParameterInfo[] parameters = methodInfo.GetParameters();
object[] array = new object[num];
int num2 = 0;
foreach (ParameterInfo parameterInfo in parameters)
{
if (parameterInfo.IsOut && !parameterInfo.ParameterType.IsByRef)
{
object obj = ((parameterInfo.Position >= mrm.ArgCount) ? null : mrm.GetArg(parameterInfo.Position));
if (obj != null)
{
object arg = call.GetArg(parameterInfo.Position);
if (arg == null)
{
throw new RemotingException("Unexpected null value in local out parameter '" + parameterInfo.Name + "'");
}
RemotingServices.UpdateOutArgObject(parameterInfo, arg, obj);
}
}
else if (parameterInfo.ParameterType.IsByRef)
{
object obj2 = ((parameterInfo.Position >= mrm.ArgCount) ? null : mrm.GetArg(parameterInfo.Position));
if (obj2 != null && !parameterInfo.ParameterType.GetElementType().IsInstanceOfType(obj2))
{
throw new InvalidCastException("Return argument '" + parameterInfo.Name + "' has an invalid type");
}
array[num2++] = obj2;
}
}
return array;
}
return new object[0];
}
// Token: 0x04000FF5 RID: 4085
private Type class_to_proxy;
// Token: 0x04000FF6 RID: 4086
internal Context _targetContext;
// Token: 0x04000FF7 RID: 4087
private MarshalByRefObject _server;
// Token: 0x04000FF8 RID: 4088
private int _targetDomainId = -1;
// Token: 0x04000FF9 RID: 4089
internal string _targetUri;
// Token: 0x04000FFA RID: 4090
internal Identity _objectIdentity;
// Token: 0x04000FFB RID: 4091
private object _objTP;
// Token: 0x04000FFC RID: 4092
private object _stubData;
}
}