Merge pull request #376 from atomia/master
[mono.git] / mcs / class / corlib / System / MarshalByRefObject.cs
index baad66470112c6d940e17ea15eb8733a56ff7f57..a2be3e6983319277b899011d41fab47174a394d0 100644 (file)
@@ -7,10 +7,7 @@
 //   Patrik Torstensson (totte_mono@yahoo.com)
 //
 // (C) Ximian, Inc.  http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 
 using System.Threading;
 using System.Runtime.Remoting;
+using System.Security.Permissions;
+using System.Runtime.InteropServices;
 
 namespace System
 {
        [Serializable]
+       [ComVisible (true)]
+       [StructLayout (LayoutKind.Sequential)]
        public abstract class MarshalByRefObject
        {
+               [NonSerialized]
                private ServerIdentity _identity; // Holds marshalling iformation of the object
 
                protected MarshalByRefObject ()
@@ -67,14 +69,18 @@ namespace System
                        set { _identity = value; }
                }
 
-               public virtual ObjRef CreateObjRef (Type type)
+               [SecurityPermission (SecurityAction.LinkDemand, Infrastructure = true)]
+               public virtual ObjRef CreateObjRef (Type requestedType)
                {
                        // This method can only be called when this object has been marshalled
                        if (_identity == null)
                                throw new RemotingException (Locale.GetText ("No remoting information was found for the object."));
-                       return _identity.CreateObjRef (type);
+                       return _identity.CreateObjRef (requestedType);
                }
 
+               // corcompare says it is "virtual final", so there is likely
+               // an internal interface in .NET.
+               [SecurityPermission (SecurityAction.LinkDemand, Infrastructure = true)]
                public object GetLifetimeService ()
                {
                        if (_identity == null)
@@ -82,9 +88,21 @@ namespace System
                        else return _identity.Lease;
                }
 
+               [SecurityPermission (SecurityAction.LinkDemand, Infrastructure = true)]
                public virtual object InitializeLifetimeService ()
                {
-                       return new System.Runtime.Remoting.Lifetime.Lease();
+                       if (_identity != null && _identity.Lease != null)
+                               return _identity.Lease;
+                       else
+                               return new System.Runtime.Remoting.Lifetime.Lease();
+               }
+
+               protected MarshalByRefObject MemberwiseClone (bool cloneIdentity)
+               {
+                       MarshalByRefObject mbr = (MarshalByRefObject) MemberwiseClone ();
+                       if (!cloneIdentity)
+                               mbr._identity = null;
+                       return mbr;
                }
        }
 }