2 // System.Reflection.FieldInfo.cs
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
9 // TODO: Mucho left to implement.
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System
.Diagnostics
;
37 using System
.Reflection
;
38 using System
.Reflection
.Emit
;
39 using System
.Globalization
;
40 using System
.Runtime
.CompilerServices
;
41 using System
.Runtime
.InteropServices
;
43 namespace System
.Reflection
{
46 [ClassInterface(ClassInterfaceType
.AutoDual
)]
47 public abstract class FieldInfo
: MemberInfo
{
48 public abstract FieldAttributes Attributes {get;}
49 public abstract RuntimeFieldHandle FieldHandle {get;}
51 protected FieldInfo () {}
53 public abstract Type FieldType { get; }
55 public abstract object GetValue(object obj
);
57 public override MemberTypes MemberType
{
58 get { return MemberTypes.Field;}
63 get {return (Attributes & FieldAttributes.Literal) != 0;}
68 get {return (Attributes & FieldAttributes.Static) != 0;}
71 public bool IsInitOnly
73 get {return (Attributes & FieldAttributes.InitOnly) != 0;}
75 public Boolean IsPublic
79 return (Attributes
& FieldAttributes
.FieldAccessMask
) == FieldAttributes
.Public
;
82 public Boolean IsPrivate
86 return (Attributes
& FieldAttributes
.FieldAccessMask
) == FieldAttributes
.Private
;
89 public Boolean IsFamily
93 return (Attributes
& FieldAttributes
.FieldAccessMask
) == FieldAttributes
.Family
;
96 public Boolean IsAssembly
100 return (Attributes
& FieldAttributes
.FieldAccessMask
) == FieldAttributes
.Assembly
;
103 public Boolean IsFamilyAndAssembly
106 return (Attributes
& FieldAttributes
.FieldAccessMask
) == FieldAttributes
.FamANDAssem
;
109 public Boolean IsFamilyOrAssembly
113 return (Attributes
& FieldAttributes
.FieldAccessMask
) == FieldAttributes
.FamORAssem
;
116 public Boolean IsPinvokeImpl
120 return (Attributes
& FieldAttributes
.PinvokeImpl
) == FieldAttributes
.PinvokeImpl
;
123 public Boolean IsSpecialName
127 return (Attributes
& FieldAttributes
.SpecialName
) == FieldAttributes
.SpecialName
;
130 public Boolean IsNotSerialized
134 return (Attributes
& FieldAttributes
.NotSerialized
) == FieldAttributes
.NotSerialized
;
138 public abstract void SetValue (object obj
, object val
, BindingFlags invokeAttr
, Binder binder
, CultureInfo culture
);
141 [DebuggerStepThrough
]
142 public void SetValue (object obj
, object value)
144 SetValue (obj
, value, 0, null, null);
147 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
148 private static extern FieldInfo
internal_from_handle (IntPtr handle
);
150 public static FieldInfo
GetFieldFromHandle (RuntimeFieldHandle handle
)
152 return internal_from_handle (handle
.Value
);
155 internal abstract int GetFieldOffset ();
157 [CLSCompliant(false)]
159 public virtual object GetValueDirect (TypedReference obj
)
161 throw new NotImplementedException ();
164 [CLSCompliant(false)]
166 public virtual void SetValueDirect (TypedReference obj
, object value)
168 throw new NotImplementedException ();
171 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
172 private extern UnmanagedMarshal
GetUnmanagedMarshal ();
174 internal object[] GetPseudoCustomAttributes ()
181 if (DeclaringType
.IsExplicitLayout
)
184 UnmanagedMarshal marshalAs
= GetUnmanagedMarshal ();
185 if (marshalAs
!= null)
190 object[] attrs
= new object [count
];
194 attrs
[count
++] = new NonSerializedAttribute ();
195 if (DeclaringType
.IsExplicitLayout
)
196 attrs
[count
++] = new FieldOffsetAttribute (GetFieldOffset ());
197 if (marshalAs
!= null)
198 attrs
[count
++] = marshalAs
.ToMarshalAsAttribute ();
203 #if NET_2_0 || BOOTSTRAP_NET_2_0
204 public virtual Type
[] OptionalCustomModifiers
{
206 throw new NotImplementedException ();
210 public virtual Type
[] RequiredCustomModifiers
{
212 throw new NotImplementedException ();
217 #if NET_2_0 || BOOTSTRAP_NET_2_0
218 public abstract FieldInfo
Mono_GetGenericFieldDefinition ();