mscorlib(4.0.0.0) API with additions
MarshalByRefObject.cs
2 using System.Reflection;
7 using System.Security;
8 using System.Threading;
9 
10 namespace System
11 {
13  [Serializable]
14  [ComVisible(true)]
15  public abstract class MarshalByRefObject
16  {
17  private object __identity;
18 
19  private object Identity
20  {
21  get
22  {
23  return __identity;
24  }
25  set
26  {
27  __identity = value;
28  }
29  }
30 
31  [SecuritySafeCritical]
32  internal IntPtr GetComIUnknown(bool fIsBeingMarshalled)
33  {
35  {
36  return RemotingServices.GetRealProxy(this).GetCOMIUnknown(fIsBeingMarshalled);
37  }
38  return Marshal.GetIUnknownForObject(this);
39  }
40 
41  [MethodImpl(MethodImplOptions.InternalCall)]
42  [SecurityCritical]
43  internal static extern IntPtr GetComIUnknown(MarshalByRefObject o);
44 
45  internal bool IsInstanceOfType(Type T)
46  {
47  return T.IsInstanceOfType(this);
48  }
49 
50  internal object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
51  {
52  Type type = GetType();
53  if (!type.IsCOMObject)
54  {
55  throw new InvalidOperationException(Environment.GetResourceString("Arg_InvokeMember"));
56  }
57  return type.InvokeMember(name, invokeAttr, binder, this, args, modifiers, culture, namedParameters);
58  }
59 
64  protected MarshalByRefObject MemberwiseClone(bool cloneIdentity)
65  {
67  if (!cloneIdentity)
68  {
69  marshalByRefObject.Identity = null;
70  }
71  return marshalByRefObject;
72  }
73 
74  [SecuritySafeCritical]
75  internal static Identity GetIdentity(MarshalByRefObject obj, out bool fServer)
76  {
77  fServer = true;
78  Identity result = null;
79  if (obj != null)
80  {
82  {
83  result = (Identity)obj.Identity;
84  }
85  else
86  {
87  fServer = false;
88  result = RemotingServices.GetRealProxy(obj).IdentityObject;
89  }
90  }
91  return result;
92  }
93 
94  internal static Identity GetIdentity(MarshalByRefObject obj)
95  {
96  bool fServer;
97  return GetIdentity(obj, out fServer);
98  }
99 
100  internal ServerIdentity __RaceSetServerIdentity(ServerIdentity id)
101  {
102  if (__identity == null)
103  {
104  if (!id.IsContextBound)
105  {
106  id.RaceSetTransparentProxy(this);
107  }
108  Interlocked.CompareExchange(ref __identity, id, null);
109  }
110  return (ServerIdentity)__identity;
111  }
112 
113  internal void __ResetServerIdentity()
114  {
115  __identity = null;
116  }
117 
121  [SecurityCritical]
122  public object GetLifetimeService()
123  {
124  return LifetimeServices.GetLease(this);
125  }
126 
130  [SecurityCritical]
131  public virtual object InitializeLifetimeService()
132  {
133  return LifetimeServices.GetLeaseInitial(this);
134  }
135 
141  [SecurityCritical]
142  public virtual ObjRef CreateObjRef(Type requestedType)
143  {
144  if (__identity == null)
145  {
146  throw new RemotingException(Environment.GetResourceString("Remoting_NoIdentityEntry"));
147  }
148  return new ObjRef(this, requestedType);
149  }
150 
151  [SecuritySafeCritical]
152  internal bool CanCastToXmlType(string xmlTypeName, string xmlTypeNamespace)
153  {
154  Type type = SoapServices.GetInteropTypeFromXmlType(xmlTypeName, xmlTypeNamespace);
155  if (type == null)
156  {
157  if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlTypeNamespace, out string typeNamespace, out string assemblyName))
158  {
159  return false;
160  }
161  string name = (typeNamespace == null || typeNamespace.Length <= 0) ? xmlTypeName : (typeNamespace + "." + xmlTypeName);
162  try
163  {
164  Assembly assembly = Assembly.Load(assemblyName);
165  type = assembly.GetType(name, throwOnError: false, ignoreCase: false);
166  }
167  catch
168  {
169  return false;
170  }
171  }
172  if (type != null)
173  {
174  return type.IsAssignableFrom(GetType());
175  }
176  return false;
177  }
178 
179  [SecuritySafeCritical]
180  internal static bool CanCastToXmlTypeHelper(RuntimeType castType, MarshalByRefObject o)
181  {
182  if (castType == null)
183  {
184  throw new ArgumentNullException("castType");
185  }
186  if (!castType.IsInterface && !castType.IsMarshalByRef)
187  {
188  return false;
189  }
190  string xmlType = null;
191  string xmlTypeNamespace = null;
192  if (!SoapServices.GetXmlTypeForInteropType(castType, out xmlType, out xmlTypeNamespace))
193  {
194  xmlType = castType.Name;
195  xmlTypeNamespace = SoapServices.CodeXmlNamespaceForClrTypeNamespace(castType.Namespace, castType.GetRuntimeAssembly().GetSimpleName());
196  }
197  return o.CanCastToXmlType(xmlType, xmlTypeNamespace);
198  }
199  }
200 }
Controls the.NET remoting lifetime services.
static Assembly Load(string assemblyString)
Loads an assembly given the long form of its name.
Definition: Assembly.cs:507
static string CodeXmlNamespaceForClrTypeNamespace(string typeNamespace, string assemblyName)
Returns the common language runtime type namespace name from the provided namespace and assembly name...
static bool DecodeXmlNamespaceForClrTypeNamespace(string inNamespace, out string typeNamespace, out string assemblyName)
Decodes the XML namespace and assembly names from the provided common language runtime namespace.
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
Definition: BindingFlags.cs:10
Definition: __Canon.cs:3
Provides several methods for using and publishing remoted objects in SOAP format.
Definition: SoapServices.cs:13
Stores all relevant information required to generate a proxy in order to communicate with a remote ob...
Definition: ObjRef.cs:19
Attaches a modifier to parameters so that binding can work with parameter signatures in which the typ...
virtual ObjRef CreateObjRef(Type requestedType)
Creates an object that contains all the relevant information required to generate a proxy used to com...
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
virtual object InitializeLifetimeService()
Obtains a lifetime service object to control the lifetime policy for this instance.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
bool IsCOMObject
Gets a value indicating whether the T:System.Type is a COM object.
Definition: Type.cs:701
MethodImplOptions
Defines the details of how a method is implemented.
MarshalByRefObject MemberwiseClone(bool cloneIdentity)
Creates a shallow copy of the current T:System.MarshalByRefObject object.
Selects a member from a list of candidates, and performs type conversion from actual argument type to...
Definition: Binder.cs:10
static bool GetXmlTypeForInteropType(Type type, out string xmlType, out string xmlTypeNamespace)
Returns XML type information that should be used when serializing the given T:System....
object GetLifetimeService()
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
static bool IsTransparentProxy(object proxy)
Returns a Boolean value that indicates whether the given object is a transparent proxy or a real obje...
static RealProxy GetRealProxy(object proxy)
Returns the real proxy backing the specified transparent proxy.
abstract object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
When overridden in a derived class, invokes the specified member, using the specified binding constra...
Specifies that the class can be serialized.
The exception that is thrown when a method call is invalid for the object's current state.
static IntPtr GetIUnknownForObject(object o)
Returns an IUnknown interface from a managed object.
Definition: Marshal.cs:1882
static Type GetInteropTypeFromXmlType(string xmlType, string xmlTypeNamespace)
Retrieves the object T:System.Type that should be used during deserialization of an unrecognized obje...
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
Provides several methods for using and publishing remoted objects and proxies. This class cannot be i...
Provides atomic operations for variables that are shared by multiple threads.
Definition: Interlocked.cs:10
The exception that is thrown when something has gone wrong during remoting.
virtual bool IsAssignableFrom(Type c)
Determines whether an instance of a specified type can be assigned to an instance of the current type...
Definition: Type.cs:2707
Enables access to objects across application domain boundaries in applications that support remoting.