**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / System.Reflection / FieldInfo.cs
blobe47a6c9b12ca4b147b640f000b9d3f74de38372d
1 //
2 // System.Reflection.FieldInfo.cs
3 //
4 // Author:
5 // Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc. http://www.ximian.com
8 //
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:
22 //
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 //
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.
35 using System;
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 {
45 [Serializable]
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;}
61 public bool IsLiteral
63 get {return (Attributes & FieldAttributes.Literal) != 0;}
66 public bool IsStatic
68 get {return (Attributes & FieldAttributes.Static) != 0;}
71 public bool IsInitOnly
73 get {return (Attributes & FieldAttributes.InitOnly) != 0;}
75 public Boolean IsPublic
77 get
79 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public;
82 public Boolean IsPrivate
84 get
86 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private;
89 public Boolean IsFamily
91 get
93 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family;
96 public Boolean IsAssembly
98 get
100 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly;
103 public Boolean IsFamilyAndAssembly
105 get {
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);
140 [DebuggerHidden]
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)]
158 [MonoTODO]
159 public virtual object GetValueDirect (TypedReference obj)
161 throw new NotImplementedException ();
164 [CLSCompliant(false)]
165 [MonoTODO]
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 ()
176 int count = 0;
178 if (IsNotSerialized)
179 count ++;
181 if (DeclaringType.IsExplicitLayout)
182 count ++;
184 UnmanagedMarshal marshalAs = GetUnmanagedMarshal ();
185 if (marshalAs != null)
186 count ++;
188 if (count == 0)
189 return null;
190 object[] attrs = new object [count];
191 count = 0;
193 if (IsNotSerialized)
194 attrs [count ++] = new NonSerializedAttribute ();
195 if (DeclaringType.IsExplicitLayout)
196 attrs [count ++] = new FieldOffsetAttribute (GetFieldOffset ());
197 if (marshalAs != null)
198 attrs [count ++] = marshalAs.ToMarshalAsAttribute ();
200 return attrs;
203 #if NET_2_0 || BOOTSTRAP_NET_2_0
204 public virtual Type[] OptionalCustomModifiers {
205 get {
206 throw new NotImplementedException ();
210 public virtual Type[] RequiredCustomModifiers {
211 get {
212 throw new NotImplementedException ();
215 #endif
217 #if NET_2_0 || BOOTSTRAP_NET_2_0
218 public abstract FieldInfo Mono_GetGenericFieldDefinition ();
219 #endif