Merge pull request #1659 from alexanderkyte/stringbuilder-referencesource
[mono.git] / mcs / class / corlib / System / RuntimeFieldHandle.cs
index dcaba2303de191f50af07e206c30dc7b76efffb7..8c552b66a3c405cca6d9a6b1c82e202fed3b5170 100644 (file)
 
 using System.Reflection;
 using System.Runtime.Serialization;
-
-#if NET_2_0
+using System.Runtime.InteropServices;
 using System.Runtime.ConstrainedExecution;
-#endif
+using System.Runtime.CompilerServices;
 
 namespace System
 {
-       [MonoTODO ("Serialization needs tests")]
+       [ComVisible (true)]
        [Serializable]
        public struct RuntimeFieldHandle : ISerializable
        {
@@ -73,12 +72,13 @@ 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 ("FieldObj", (MonoField) FieldInfo.GetFieldFromHandle (this), typeof (MonoField));
                }
 
-#if NET_2_0
                [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
-#endif
                public override bool Equals (object obj)
                {
                        if (obj == null || GetType () != obj.GetType ())
@@ -87,9 +87,7 @@ namespace System
                        return value == ((RuntimeFieldHandle)obj).Value;
                }
 
-#if NET_2_0
                [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
-#endif
                public bool Equals (RuntimeFieldHandle handle)
                {
                        return value == handle.Value;
@@ -99,5 +97,31 @@ namespace System
                {
                        return value.GetHashCode ();
                }
+
+               public static bool operator == (RuntimeFieldHandle left, RuntimeFieldHandle right)
+               {
+                       return left.Equals (right);
+               }
+
+               public static bool operator != (RuntimeFieldHandle left, RuntimeFieldHandle right)
+               {
+                       return !left.Equals (right);
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               static extern void SetValueInternal (FieldInfo fi, object obj, object value);
+
+               internal static void SetValue (RtFieldInfo field, Object obj, Object value, RuntimeType fieldType, FieldAttributes fieldAttr, RuntimeType declaringType, ref bool domainInitialized)
+               {
+                       SetValueInternal (field, obj, value);
+               }
+
+               unsafe internal static Object GetValueDirect (RtFieldInfo field, RuntimeType fieldType, void *pTypedRef, RuntimeType contextType)
+               {
+                       throw new NotImplementedException ("GetValueDirect");
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               static unsafe extern internal void SetValueDirect (RtFieldInfo field, RuntimeType fieldType, void* pTypedRef, Object value, RuntimeType contextType);
        }
 }