Tue May 14 13:31:17 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / FieldBuilder.cs
1
2
3 //
4 // System.Reflection.Emit/FieldBuilder.cs
5 //
6 // Author:
7 //   Paolo Molaro (lupus@ximian.com)
8 //
9 // (C) 2001 Ximian, Inc.  http://www.ximian.com
10 //
11
12 using System;
13 using System.Reflection;
14 using System.Reflection.Emit;
15 using System.Globalization;
16 using System.Runtime.CompilerServices;
17
18 namespace System.Reflection.Emit {
19         public sealed class FieldBuilder : FieldInfo {
20                 private FieldAttributes attrs;
21                 private Type type;
22                 private String name;
23                 private object def_value;
24                 private int offset;
25                 private int table_idx;
26                 internal TypeBuilder typeb;
27                 private byte[] rva_data;
28                 private CustomAttributeBuilder[] cattrs;
29
30                 internal FieldBuilder (TypeBuilder tb, string fieldName, Type type, FieldAttributes attributes) {
31                         attrs = attributes;
32                         name = fieldName;
33                         this.type = type;
34                         offset = -1;
35                         typeb = tb;
36                         table_idx = tb.get_next_table_index (0x04, true);
37                 }
38
39                 public override FieldAttributes Attributes {
40                         get {return attrs;}
41                 }
42                 public override Type DeclaringType {
43                         get {return typeb;}
44                 }
45                 public override RuntimeFieldHandle FieldHandle {
46                         get {return new RuntimeFieldHandle();}
47                 }
48                 public override Type FieldType {
49                         get {return type;}
50                 }
51                 public override string Name {
52                         get {return name;}
53                 }
54                 public override Type ReflectedType {
55                         get {return typeb;}
56                 }
57
58                 public override object[] GetCustomAttributes(bool inherit) {
59                         return null;
60                 }
61                 public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
62                         return null;
63                 }
64                 public FieldToken GetToken() {
65                         return new FieldToken (0x04000000 | table_idx);
66                 }
67                 public override object GetValue(object obj) {
68                         return null;
69                 }
70                 public override bool IsDefined( Type attributeType, bool inherit) {
71                         return false;
72                 }
73                 internal void SetRVAData (byte[] data) {
74                         rva_data = (byte[])data.Clone ();
75                 }
76                 public void SetConstant( object defaultValue) {
77                         /*if (defaultValue.GetType() != type)
78                                 throw new ArgumentException ("Constant doesn't match field type");*/
79                         def_value = defaultValue;
80                 }
81                 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
82                         string attrname = customBuilder.Ctor.ReflectedType.FullName;
83                         if (attrname == "System.Runtime.InteropServices.FieldOffsetAttribute") {
84                                 byte[] data = customBuilder.Data;
85                                 offset = (int)data [2];
86                                 offset |= ((int)data [3]) << 8;
87                                 offset |= ((int)data [4]) << 16;
88                                 offset |= ((int)data [5]) << 24;
89                                 return;
90                         } else if (attrname == "System.NonSerializedAttribute") {
91                                 attrs |= FieldAttributes.NotSerialized;
92                                 return;
93                         }
94                         if (cattrs != null) {
95                                 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
96                                 cattrs.CopyTo (new_array, 0);
97                                 new_array [cattrs.Length] = customBuilder;
98                                 cattrs = new_array;
99                         } else {
100                                 cattrs = new CustomAttributeBuilder [1];
101                                 cattrs [0] = customBuilder;
102                         }
103                 }
104                 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
105                         SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
106                 }
107                 public void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
108                 }
109                 public void SetOffset( int iOffset) {
110                         offset = iOffset;
111                 }
112                 public override void SetValue( object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture) {
113                 }
114
115         }
116 }
117