2004-01-04 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / class / corlib / System.Reflection / FieldInfo.cs
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.
10 //
11
12 using System;
13 using System.Reflection;
14 using System.Reflection.Emit;
15 using System.Globalization;
16 using System.Runtime.CompilerServices;
17 using System.Runtime.InteropServices;
18
19 namespace System.Reflection {
20
21         [Serializable]
22         [ClassInterface(ClassInterfaceType.AutoDual)]
23         public abstract class FieldInfo : MemberInfo {
24                 public abstract FieldAttributes Attributes {get;}
25                 public abstract RuntimeFieldHandle FieldHandle {get;}
26
27                 internal FieldInfo () {}
28                 
29                 public abstract Type FieldType { get; }
30
31                 public abstract object GetValue(object obj);
32
33                 public override MemberTypes MemberType {
34                         get { return MemberTypes.Field;}
35                 }
36
37                 public bool IsLiteral
38                 {
39                         get {return (Attributes & FieldAttributes.Literal) != 0;}
40                 } 
41
42                 public bool IsStatic
43                 {
44                         get {return (Attributes & FieldAttributes.Static) != 0;}
45                 } 
46
47                 public bool IsInitOnly
48                 {
49                         get {return (Attributes & FieldAttributes.InitOnly) != 0;}
50                 } 
51                 public Boolean IsPublic
52                 { 
53                         get
54                         {
55                                 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public;
56                         }
57                 }
58                 public Boolean IsPrivate
59                 {
60                         get
61                         {
62                                 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private;
63                         }
64                 }
65                 public Boolean IsFamily
66                 {
67                         get
68                         {
69                                 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family;
70                         }
71                 }
72                 public Boolean IsAssembly
73                 {
74                         get
75                         {
76                                 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly;
77                         }
78                 }
79                 public Boolean IsFamilyAndAssembly
80                 {
81                         get {
82                                 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem;
83                         }
84                 }
85                 public Boolean IsFamilyOrAssembly
86                 {
87                         get
88                         {
89                                 return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem;
90                         }
91                 }
92                 public Boolean IsPinvokeImpl
93                 {
94                         get
95                         {
96                                 return (Attributes & FieldAttributes.PinvokeImpl) == FieldAttributes.PinvokeImpl;
97                         }
98                 }
99                 public Boolean IsSpecialName
100                 {
101                         get
102                         {
103                                 return (Attributes & FieldAttributes.SpecialName) == FieldAttributes.SpecialName;
104                         }
105                 }
106                 public Boolean IsNotSerialized
107                 {
108                         get
109                         {
110                                 return (Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized;
111                         }
112                 }
113
114                 public abstract void SetValue (object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture);
115
116                 public void SetValue (object obj, object value)
117                 {
118                         SetValue (obj, value, 0, null, null);
119                 }
120
121                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
122                 private static extern FieldInfo internal_from_handle (IntPtr handle);
123
124                 public static FieldInfo GetFieldFromHandle (RuntimeFieldHandle handle)
125                 {
126                         return internal_from_handle (handle.Value);
127                 }
128         }
129 }