Merge pull request #3692 from lateralusX/jlorenss/win-api-family-support-libmono
[mono.git] / mcs / class / corlib / System / RuntimeMethodHandle.cs
index 905e96939691b98910183a733a5e8670100c83b5..1a3edeeb16e4b8a18f4709466c902c72d12420da 100644 (file)
 using System.Reflection;
 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
 {
-       [MonoTODO ("Serialization needs tests")]
+       [ComVisible (true)]
        [Serializable]
        public struct RuntimeMethodHandle : ISerializable
        {
@@ -73,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));
                }
 
@@ -85,9 +87,7 @@ namespace System
                        return GetFunctionPointer (value);
                }
 
-#if NET_2_0
                [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
-#endif
                public override bool Equals (object obj)
                {
                        if (obj == null || GetType () != obj.GetType ())
@@ -96,9 +96,7 @@ namespace System
                        return value == ((RuntimeMethodHandle)obj).Value;
                }
 
-#if NET_2_0
                [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
-#endif
                public bool Equals (RuntimeMethodHandle handle)
                {
                        return value == handle.Value;
@@ -108,5 +106,34 @@ namespace System
                {
                        return value.GetHashCode ();
                }
+
+               public static bool operator == (RuntimeMethodHandle left, RuntimeMethodHandle right)
+               {
+                       return left.Equals (right);
+               }
+
+               public static bool operator != (RuntimeMethodHandle left, RuntimeMethodHandle right)
+               {
+                       return !left.Equals (right);
+               }
+
+               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;
+               }
        }
 }