4 // System.Reflection.Emit/FieldBuilder.cs
7 // Paolo Molaro (lupus@ximian.com)
9 // (C) 2001 Ximian, Inc. http://www.ximian.com
13 using System.Reflection;
14 using System.Reflection.Emit;
15 using System.Globalization;
16 using System.Runtime.CompilerServices;
18 namespace System.Reflection.Emit {
19 public sealed class FieldBuilder : FieldInfo {
20 private FieldAttributes attrs;
23 private object def_value;
25 private int table_idx;
26 internal TypeBuilder typeb;
27 private byte[] rva_data;
28 private CustomAttributeBuilder[] cattrs;
30 internal FieldBuilder (TypeBuilder tb, string fieldName, Type type, FieldAttributes attributes) {
36 table_idx = tb.get_next_table_index (0x04, true);
39 public override FieldAttributes Attributes {
42 public override Type DeclaringType {
45 public override RuntimeFieldHandle FieldHandle {
46 get {return new RuntimeFieldHandle();}
48 public override Type FieldType {
51 public override string Name {
54 public override Type ReflectedType {
58 public override object[] GetCustomAttributes(bool inherit) {
61 public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
64 public FieldToken GetToken() {
65 return new FieldToken (0x04000000 | table_idx);
67 public override object GetValue(object obj) {
70 public override bool IsDefined( Type attributeType, bool inherit) {
73 internal void SetRVAData (byte[] data) {
74 rva_data = (byte[])data.Clone ();
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;
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;
92 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
93 cattrs.CopyTo (new_array, 0);
94 new_array [cattrs.Length] = customBuilder;
97 cattrs = new CustomAttributeBuilder [1];
98 cattrs [0] = customBuilder;
101 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
102 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
104 public void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
106 public void SetOffset( int iOffset) {
109 public override void SetValue( object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture) {