[runtime] Updates comments.
[mono.git] / mcs / class / corlib / System.Reflection / MonoField.cs
index 5a0572936adf4727b1ce13fddf8734733707c4a4..117eea363fd520e7c1998c4aedd28d2f0f580a37 100644 (file)
@@ -41,8 +41,24 @@ using System.Runtime.Serialization;
 
 namespace System.Reflection {
 
+       abstract class RuntimeFieldInfo : FieldInfo
+       {
+               internal BindingFlags BindingFlags {
+                       get {
+                               return 0;
+                       }
+               }
+       }
+
+       abstract class RtFieldInfo : RuntimeFieldInfo
+       {
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern object UnsafeGetValue (object obj);
+       }
+
        [Serializable]
-       internal class MonoField : FieldInfo, ISerializable {
+       [StructLayout (LayoutKind.Sequential)]
+       internal class MonoField : RtFieldInfo, ISerializable {
                internal IntPtr klass;
                internal RuntimeFieldHandle fhandle;
                string name;
@@ -145,14 +161,11 @@ namespace System.Reflection {
                        if (IsLiteral)
                                throw new FieldAccessException ("Cannot set a constant field");
                        if (binder == null)
-                               binder = Binder.DefaultBinder;
+                               binder = Type.DefaultBinder;
                        CheckGeneric ();
                        if (val != null) {
-                               object newVal;
-                               newVal = binder.ChangeType (val, FieldType, culture);
-                               if (newVal == null)
-                                       throw new ArgumentException ("Object type " + val.GetType() + " cannot be converted to target type: " + FieldType, "val");
-                               val = newVal;
+                               RuntimeType fieldType = (RuntimeType) FieldType;
+                               val = fieldType.CheckValue (val, binder, culture, invokeAttr);
                        }
                        SetValueInternal (this, obj, val);
                }
@@ -178,11 +191,9 @@ namespace System.Reflection {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public override extern object GetRawConstantValue ();
 
-#if NET_4_0
                public override IList<CustomAttributeData> GetCustomAttributesData () {
                        return CustomAttributeData.GetCustomAttributes (this);
                }
-#endif
 
                void CheckGeneric () {
                        if (DeclaringType.ContainsGenericParameters)