Merge pull request #1659 from alexanderkyte/stringbuilder-referencesource
[mono.git] / mcs / class / corlib / System / RuntimeMethodHandle.cs
index bff94af25a8a51815e0bf7430856adbc0015fe2f..1a3edeeb16e4b8a18f4709466c902c72d12420da 100644 (file)
@@ -33,17 +33,12 @@ using System.Runtime.Serialization;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Security.Permissions;
-
-#if NET_2_0
 using System.Runtime.ConstrainedExecution;
-#endif
+using System.Text;
 
 namespace System
 {
-#if NET_2_0
        [ComVisible (true)]
-#endif
-       [MonoTODO ("Serialization needs tests")]
        [Serializable]
        public struct RuntimeMethodHandle : ISerializable
        {
@@ -77,6 +72,9 @@ namespace System
                        if (info == null)
                                throw new ArgumentNullException ("info");
 
+                       if (value == IntPtr.Zero)
+                               throw new SerializationException ("Object fields may not be properly initialized");
+
                        info.AddValue ("MethodObj", (MonoMethod) MethodBase.GetMethodFromHandle (this), typeof (MonoMethod));
                }
 
@@ -89,7 +87,6 @@ namespace System
                        return GetFunctionPointer (value);
                }
 
-#if NET_2_0
                [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
                public override bool Equals (object obj)
                {
@@ -119,6 +116,24 @@ namespace System
                {
                        return !left.Equals (right);
                }
-#endif
+
+               internal static string ConstructInstantiation (RuntimeMethodInfo method, TypeNameFormatFlags format)
+               {
+                       var sb = new StringBuilder ();
+                       var gen_params = method.GetGenericArguments ();
+                       sb.Append ("[");
+                       for (int j = 0; j < gen_params.Length; j++) {
+                               if (j > 0)
+                                       sb.Append (",");
+                               sb.Append (gen_params [j].Name);
+                       }
+                       sb.Append ("]");
+                       return sb.ToString ();
+               }
+
+               internal bool IsNullHandle ()
+               {
+                       return value == IntPtr.Zero;
+               }
        }
 }