[corlib] UnitySerialization from reference sources
authorMarek Safar <marek.safar@gmail.com>
Fri, 13 Feb 2015 13:45:46 +0000 (14:45 +0100)
committerMarek Safar <marek.safar@gmail.com>
Fri, 13 Feb 2015 13:45:46 +0000 (14:45 +0100)
mcs/class/corlib/ReferenceSources/Empty.cs [deleted file]
mcs/class/corlib/System.Reflection/Assembly.cs
mcs/class/corlib/System.Reflection/Module.cs
mcs/class/corlib/System.Reflection/MonoAssembly.cs
mcs/class/corlib/System.Reflection/MonoModule.cs
mcs/class/corlib/System/DBNull.cs [deleted file]
mcs/class/corlib/System/MonoType.cs
mcs/class/corlib/System/Type.cs
mcs/class/corlib/System/UnitySerializationHolder.cs [deleted file]
mcs/class/corlib/corlib.dll.sources

diff --git a/mcs/class/corlib/ReferenceSources/Empty.cs b/mcs/class/corlib/ReferenceSources/Empty.cs
deleted file mode 100644 (file)
index ceff8d5..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-namespace System
-{
-       using System;
-       using System.Runtime.Remoting;
-       using System.Runtime.Serialization;
-
-       [Serializable]
-       internal sealed class Empty
-       {
-               private Empty() {
-               }
-       }
-}
\ No newline at end of file
index 5401c0b7bcafff392dc649c0737d0a32a8925e9c..f1ba85efdd76de8d9cf04bf3c0715fb3d7515dcb 100644 (file)
@@ -201,13 +201,9 @@ namespace System.Reflection {
                        }
                }
 
-               [SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
                public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
                {
-                       if (info == null)
-                               throw new ArgumentNullException ("info");
-
-                       UnitySerializationHolder.GetAssemblyData (this, info, context);
+                       throw new NotImplementedException ();
                }
 
                public virtual bool IsDefined (Type attributeType, bool inherit)
index a414acc3d5fa01769f2b910492e5254f2d5f7bd9..79bddc252ae00193b1fe70f2ab0a332929efe4c1 100644 (file)
@@ -122,10 +122,7 @@ namespace System.Reflection {
                [SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
                public virtual void GetObjectData (SerializationInfo info, StreamingContext context) 
                {
-                       if (info == null)
-                               throw new ArgumentNullException ("info");
-
-                       UnitySerializationHolder.GetModuleData (this, info, context);
+                       throw new NotImplementedException ();
                }
 
                [ComVisible (true)]
index 80eb4c79d76c8f2269af0b0a6ad8f18fd7c43b91..cb9faca36dceb08ceb9f866ecdda437ccdb38133 100644 (file)
@@ -34,14 +34,30 @@ using System.Runtime.InteropServices;
 using System.Reflection.Emit;
 #endif
 using System.Collections.Generic;
+using System.Runtime.Serialization;
 
 namespace System.Reflection {
 
+       abstract class RuntimeAssembly : Assembly
+       {
+               public override void GetObjectData (SerializationInfo info, StreamingContext context)
+               {
+                       if (info == null)
+                               throw new ArgumentNullException ("info");
+
+                       UnitySerializationHolder.GetUnitySerializationInfo (info,
+                                                               UnitySerializationHolder.AssemblyUnity,
+                                                               this.FullName,
+                                                               this);
+               }
+       }
+
        [ComVisible (true)]
        [ComDefaultInterfaceAttribute (typeof (_Assembly))]
        [Serializable]
        [ClassInterface(ClassInterfaceType.None)]
-       class MonoAssembly : Assembly {
+       class MonoAssembly : RuntimeAssembly
+       {
                public
                override
                Type GetType (string name, bool throwOnError, bool ignoreCase)
index 19c756a0d65ce88db213e25dafd0c93350eb2d3e..f710da52cdd977cc6333f5947313b187bec60de0 100644 (file)
@@ -34,7 +34,7 @@ using System.Runtime.InteropServices;
 using System.Security.Cryptography.X509Certificates;
 using System.Security;
 using System.Security.Permissions;
-
+using System.Runtime.Serialization;
 
 namespace System.Reflection {
 
@@ -267,6 +267,14 @@ namespace System.Reflection {
                                return res;
                }
 
+               public override void GetObjectData (SerializationInfo info, StreamingContext context)
+               {
+                       if (info == null)
+                               throw new ArgumentNullException ("info");
+
+                       UnitySerializationHolder.GetUnitySerializationInfo (info, UnitySerializationHolder.ModuleUnity, this.ScopeName, this.GetRuntimeAssembly ());
+               }
+
 #if !NET_2_1
 
                public
@@ -291,5 +299,10 @@ namespace System.Reflection {
                public override IList<CustomAttributeData> GetCustomAttributesData () {
                        return CustomAttributeData.GetCustomAttributes (this);
                }
+
+               internal RuntimeAssembly GetRuntimeAssembly ()
+               {
+                       return (RuntimeAssembly)assembly;
+               }
        }
 }
diff --git a/mcs/class/corlib/System/DBNull.cs b/mcs/class/corlib/System/DBNull.cs
deleted file mode 100644 (file)
index e730cc8..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-//
-// System.DBNull.cs
-//
-// Authors:
-//   Duncan Mak (duncan@ximian.com)
-//   Ben Maurer (bmaurer@users.sourceforge.net)
-//
-// (C) 2002 Ximian, Inc. http://www.ximian.com
-// (C) 2003 Ben Maurer
-//
-
-//
-// Copyright (C) 2004 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
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Runtime.Serialization;
-using System.Runtime.InteropServices;
-
-namespace System
-{
-       [Serializable]
-       [ComVisible (true)]
-       public sealed class DBNull : ISerializable, IConvertible
-       {
-               // Fields
-               public static readonly DBNull Value = new DBNull ();
-
-               // Private constructor
-               private DBNull ()
-               {
-               }
-
-               private DBNull (SerializationInfo info, StreamingContext context)
-               {
-                       throw new NotSupportedException ();
-               }
-
-               // Methods
-               public void GetObjectData (SerializationInfo info, StreamingContext context)
-               {
-                       UnitySerializationHolder.GetDBNullData (this, info, context);
-               }
-
-               public TypeCode GetTypeCode ()
-               {
-                       return TypeCode.DBNull;
-               }
-
-               bool IConvertible.ToBoolean (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }                       
-
-               byte IConvertible.ToByte (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               char IConvertible.ToChar (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               DateTime IConvertible.ToDateTime (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               decimal IConvertible.ToDecimal (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-               
-               double IConvertible.ToDouble (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               short IConvertible.ToInt16 (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               int IConvertible.ToInt32 (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               long IConvertible.ToInt64 (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               sbyte IConvertible.ToSByte (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               float IConvertible.ToSingle (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               object IConvertible.ToType (Type targetType, IFormatProvider provider)
-               {
-                       if (targetType == typeof (string))
-                               return String.Empty;
-                       if (targetType == typeof (DBNull))
-                               return this;
-                       throw new InvalidCastException ();
-               }
-
-               ushort IConvertible.ToUInt16 (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               uint IConvertible.ToUInt32 (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               ulong IConvertible.ToUInt64 (IFormatProvider provider)
-               {
-                       throw new InvalidCastException ();
-               }
-
-               public override string ToString ()
-               {
-                       return String.Empty;
-               }
-
-               public string ToString (IFormatProvider provider)
-               {
-                       return String.Empty;
-               }
-       }
-}
index b7e0ee70e00bc72ee57e9e387672c9584192b6dc..d415645f5e2039d2016bef7d664b39f53a4ed2d3 100644 (file)
@@ -51,7 +51,16 @@ namespace System
                
        abstract class RuntimeType : TypeInfo
        {
+               internal RuntimeAssembly GetRuntimeAssembly ()
+               {
+                       return (RuntimeAssembly) Assembly;
+               }
 
+               internal virtual bool IsSzArray {
+                       get {
+                               return IsArrayImpl () && GetArrayRank () == 1;
+                       }
+               }
        }
 
        [Serializable]
@@ -656,7 +665,7 @@ namespace System
 
                public void GetObjectData(SerializationInfo info, StreamingContext context)
                {
-                       UnitySerializationHolder.GetTypeData (this, info, context);
+                       UnitySerializationHolder.GetUnitySerializationInfo(info, this);
                }
 
                public override string ToString()
index bbd5bbbc7492ef11b359d090b8b437f07302f59d..1475736d7d5de3aa29a3fc59fbddcb25e8b3e0bc 100644 (file)
@@ -1618,6 +1618,16 @@ namespace System {
                        }
                }
 
+               internal Type GetRootElementType()
+               {
+                       Type rootElementType = this;
+
+                       while (rootElementType.HasElementType)
+                               rootElementType = rootElementType.GetElementType();
+
+                       return rootElementType;
+               }
+
 #if !MOBILE
                void _Type.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
                {
diff --git a/mcs/class/corlib/System/UnitySerializationHolder.cs b/mcs/class/corlib/System/UnitySerializationHolder.cs
deleted file mode 100644 (file)
index 33b323c..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-//
-// System.UnitySerializationHolder.cs
-//
-// Author:
-//   Lluis Sanchez Gual (lsg@ctv.es)
-//
-// (C) 2003 Lluis Sanchez Gual
-
-//
-// Copyright (C) 2004 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
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Reflection;
-using System.Runtime.Serialization;
-
-namespace System
-{
-       [Serializable]
-       internal class UnitySerializationHolder : IObjectReference, ISerializable
-       {
-               string _data;
-               UnityType _unityType;
-               string _assemblyName;
-
-               // FIXME: there must be other types that use UnitySerializationHolder for
-               // serialization, but I don't know yet which ones.
-
-               enum UnityType: byte
-               {
-                       DBNull = 2,
-                       Type = 4,
-                       Module = 5,
-                       Assembly = 6
-               }
-
-               UnitySerializationHolder (SerializationInfo info, StreamingContext ctx)
-               {
-                       _data = info.GetString ("Data");
-                       _unityType = (UnityType) info.GetInt32 ("UnityType");
-                       _assemblyName = info.GetString ("AssemblyName");
-               }
-
-               public static void GetTypeData (Type instance, SerializationInfo info, StreamingContext ctx)
-               {
-                       info.AddValue ("Data", instance.FullName);
-                       info.AddValue ("UnityType", (int) UnityType.Type);
-                       info.AddValue ("AssemblyName", instance.Assembly.FullName);
-                       info.SetType (typeof (UnitySerializationHolder));
-               }
-
-               public static void GetDBNullData (DBNull instance, SerializationInfo info, StreamingContext ctx)
-               {
-                       info.AddValue ("Data", null);
-                       info.AddValue ("UnityType", (int) UnityType.DBNull);
-                       info.AddValue ("AssemblyName", instance.GetType().Assembly.FullName);
-                       info.SetType (typeof (UnitySerializationHolder));
-               }
-
-               public static void GetAssemblyData (Assembly instance, SerializationInfo info, StreamingContext ctx)
-               {
-                       info.AddValue ("Data", instance.FullName);
-                       info.AddValue ("UnityType", (int) UnityType.Assembly);
-                       info.AddValue ("AssemblyName", instance.FullName);
-                       info.SetType (typeof (UnitySerializationHolder));
-               }
-
-               public static void GetModuleData (Module instance, SerializationInfo info, StreamingContext ctx)
-               {
-                       info.AddValue ("Data", instance.ScopeName);
-                       info.AddValue ("UnityType", (int) UnityType.Module);
-                       info.AddValue ("AssemblyName", instance.Assembly.FullName);
-                       info.SetType (typeof (UnitySerializationHolder));
-               }
-
-               public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
-               {
-                       // Not needed.
-                       throw new NotSupportedException();
-               }
-
-               public virtual object GetRealObject (StreamingContext context)
-               {
-                       switch (_unityType) {
-                       case UnityType.Type: {
-                               Assembly assembly = Assembly.Load (_assemblyName);
-                               return assembly.GetType (_data);
-                       }
-                       case UnityType.DBNull:
-                               return DBNull.Value;
-                       case UnityType.Module: {
-                               Assembly assembly = Assembly.Load (_assemblyName);
-                               return assembly.GetModule (_data);
-                       }
-                       case UnityType.Assembly:
-                               return Assembly.Load (_data);
-                       default:
-                               throw new NotSupportedException (Locale.GetText
-                                       ("UnitySerializationHolder does not support this type."));
-                       }
-               }
-       }
-}
index cc33b47564409c14b8ddebc3f1e7e15094ae5519..a3f8bcda68add035798204254598f8fa6c39b19b 100644 (file)
@@ -130,7 +130,6 @@ System/ContextStaticAttribute.cs
 System/ControlCharacters.cs
 System/CrossAppDomainDelegate.cs
 System/DataMisalignedException.cs
-System/DBNull.cs
 System/Delegate.cs
 System/DelegateSerializationHolder.cs
 System/DivideByZeroException.cs
@@ -263,7 +262,6 @@ System/UIntPtr.cs
 System/UnauthorizedAccessException.cs
 System/UnhandledExceptionEventArgs.cs
 System/UnhandledExceptionEventHandler.cs
-System/UnitySerializationHolder.cs
 System/ValueType.cs
 System/Variant.cs
 System/Void.cs
@@ -1435,7 +1433,6 @@ ReferenceSources/BCLDebug.cs
 ReferenceSources/CalendarData.cs
 ReferenceSources/CompatibilitySwitches.cs
 ReferenceSources/CultureData.cs
-ReferenceSources/Empty.cs
 ReferenceSources/Environment.cs
 ReferenceSources/ExecutionContext.cs
 ReferenceSources/HashHelpers.cs
@@ -1459,6 +1456,8 @@ ReferenceSources/JitHelpers.cs
 ../../../external/referencesource/mscorlib/system/datetimeoffset.cs
 ../../../external/referencesource/mscorlib/system/dayofweek.cs
 ../../../external/referencesource/mscorlib/system/decimal.cs
+../../../external/referencesource/mscorlib/system/dbnull.cs
+../../../external/referencesource/mscorlib/system/empty.cs
 ../../../external/referencesource/mscorlib/system/guid.cs
 ../../../external/referencesource/mscorlib/system/int16.cs
 ../../../external/referencesource/mscorlib/system/int32.cs
@@ -1476,6 +1475,7 @@ ReferenceSources/JitHelpers.cs
 ../../../external/referencesource/mscorlib/system/uint16.cs
 ../../../external/referencesource/mscorlib/system/uint32.cs
 ../../../external/referencesource/mscorlib/system/uint64.cs
+../../../external/referencesource/mscorlib/system/unityserializationholder.cs
 ../../../external/referencesource/mscorlib/system/version.cs
 
 ../../../external/referencesource/mscorlib/system/collections/arraylist.cs