3 // System.Reflection/MonoField.cs
4 // The class used to represent Fields from the mono runtime.
7 // Paolo Molaro (lupus@ximian.com)
9 // (C) 2001 Ximian, Inc. http://www.ximian.com
13 using System.Globalization;
14 using System.Runtime.CompilerServices;
15 using System.Runtime.InteropServices;
17 namespace System.Reflection {
19 internal class MonoField : FieldInfo {
20 internal IntPtr klass;
21 internal RuntimeFieldHandle fhandle;
24 FieldAttributes attrs;
26 public override FieldAttributes Attributes {
31 public override RuntimeFieldHandle FieldHandle {
37 public override Type FieldType {
43 [MethodImplAttribute(MethodImplOptions.InternalCall)]
44 private extern Type GetParentType (bool declaring);
46 public override Type ReflectedType {
48 return GetParentType (false);
51 public override Type DeclaringType {
53 return GetParentType (true);
56 public override string Name {
62 public override bool IsDefined (Type attributeType, bool inherit) {
63 return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
66 public override object[] GetCustomAttributes( bool inherit) {
67 return MonoCustomAttrs.GetCustomAttributes (this, inherit);
69 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
70 return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
73 [MethodImplAttribute(MethodImplOptions.InternalCall)]
74 private extern object GetValueInternal (object obj);
76 public override object GetValue (object obj)
78 return GetValueInternal (obj);
81 public override string ToString () {
82 return String.Format ("{0} {1}", type, name);
85 [MethodImplAttribute(MethodImplOptions.InternalCall)]
86 private static extern void SetValueInternal (FieldInfo fi, object obj, object value);
88 public override void SetValue (object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
90 if (!IsStatic && obj == null)
91 throw new ArgumentNullException ("obj");
93 binder = Binder.DefaultBinder;
95 val = binder.ChangeType (val, type, culture);
97 throw new ArgumentException ("Object type cannot be converted to target type.", "val");
99 SetValueInternal (this, obj, val);