2004-04-24 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
[mono.git] / mcs / class / corlib / System / MarshalByRefObject.cs
1 //
2 // System.MarshalByRefObject.cs
3 //
4 // Authors:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //   Lluis Sanchez Gual (lsg@ctv.es)
7 //   Patrik Torstensson (totte_mono@yahoo.com)
8 //
9 // (C) Ximian, Inc.  http://www.ximian.com
10 //
11
12 using System.Threading;
13 using System.Runtime.Remoting;
14
15 namespace System
16 {
17         [Serializable]
18         public abstract class MarshalByRefObject
19         {
20                 private ServerIdentity _identity; // Holds marshalling iformation of the object
21
22                 protected MarshalByRefObject ()
23                 {
24                 }
25
26                 internal Identity GetObjectIdentity (MarshalByRefObject obj, out bool IsClient)
27                 {
28                         IsClient = false;
29                         Identity objId = null;
30
31                         if (RemotingServices.IsTransparentProxy (obj)) {
32                                 objId = RemotingServices.GetRealProxy (obj).ObjectIdentity;
33                                 IsClient = true;
34                         }
35                         else {
36                                 objId = obj.ObjectIdentity;
37                         }
38
39                         return objId;
40                 }
41
42                 internal ServerIdentity ObjectIdentity {
43                         get { return _identity; }
44                         set { _identity = value; }
45                 }
46
47                 public virtual ObjRef CreateObjRef (Type type)
48                 {
49                         // This method can only be called when this object has been marshalled
50                         if (_identity == null)
51                                 throw new RemotingException (Locale.GetText ("No remoting information was found for the object."));
52                         return _identity.CreateObjRef (type);
53                 }
54
55                 public object GetLifetimeService ()
56                 {
57                         if (_identity == null)
58                                 return null;
59                         else return _identity.Lease;
60                 }
61
62                 public virtual object InitializeLifetimeService ()
63                 {
64                         return new System.Runtime.Remoting.Lifetime.Lease();
65                 }
66         }
67 }