using System.Runtime.Serialization;
using System.Runtime.InteropServices;
-
-#if NET_2_0
using System.Runtime.ConstrainedExecution;
-#endif
namespace System
{
-#if NET_2_0
[ComVisible (true)]
-#endif
- [MonoTODO ("Serialization needs tests")]
[Serializable]
public struct RuntimeTypeHandle : ISerializable
{
if (info == null)
throw new ArgumentNullException ("info");
+ if (value == IntPtr.Zero)
+ throw new SerializationException ("Object fields may not be properly initialized");
+
info.AddValue ("TypeObj", Type.GetTypeHandle (this), typeof (MonoType));
}
-#if NET_2_0
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
public override bool Equals (object obj)
{
return value.GetHashCode ();
}
- public static bool operator == (RuntimeTypeHandle left, RuntimeTypeHandle right)
+ public static bool operator == (RuntimeTypeHandle left, Object right)
{
- return left.Equals (right);
+ return (right != null) && (right is RuntimeTypeHandle) && left.Equals ((RuntimeTypeHandle)right);
}
- public static bool operator != (RuntimeTypeHandle left, RuntimeTypeHandle right)
+ public static bool operator != (RuntimeTypeHandle left, Object right)
{
- return !left.Equals (right);
+ return (right == null) || !(right is RuntimeTypeHandle) || !left.Equals ((RuntimeTypeHandle)right);
}
public static bool operator == (Object left, RuntimeTypeHandle right)
[CLSCompliant (false)]
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
- public ModuleHandle GetModuleHandle () {
+ public ModuleHandle GetModuleHandle ()
+ {
+ // Although MS' runtime is crashing here, we prefer throwing an exception.
+ // The check is needed because Type.GetTypeFromHandle returns null
+ // for zero handles.
+ if (value == IntPtr.Zero)
+ throw new InvalidOperationException ("Object fields may not be properly initialized");
+
return Type.GetTypeFromHandle (this).Module.ModuleHandle;
}
-#endif
}
}