Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FieldBuilder.cs « System.Reflection.Emit « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ebe66f7ee5c379163d7cd6a7625ac44a817b138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

//
// System.Reflection.Emit/FieldBuilder.cs
//
// Author:
//   Paolo Molaro (lupus@ximian.com)
//
// (C) 2001-2002 Ximian, Inc.  http://www.ximian.com
//

using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System.Reflection.Emit {
	public sealed class FieldBuilder : FieldInfo {
		private FieldAttributes attrs;
		private Type type;
		private String name;
		private object def_value;
		private int offset;
		private int table_idx;
		internal TypeBuilder typeb;
		private byte[] rva_data;
		private CustomAttributeBuilder[] cattrs;
		private UnmanagedMarshal marshal_info;

		internal FieldBuilder (TypeBuilder tb, string fieldName, Type type, FieldAttributes attributes) {
			attrs = attributes;
			name = fieldName;
			this.type = type;
			offset = -1;
			typeb = tb;
			table_idx = tb.get_next_table_index (this, 0x04, true);
		}

		public override FieldAttributes Attributes {
			get {return attrs;}
		}
		public override Type DeclaringType {
			get {return typeb;}
		}
		public override RuntimeFieldHandle FieldHandle {
			get {return new RuntimeFieldHandle();}
		}
		public override Type FieldType {
			get {return type;}
		}
		public override string Name {
			get {return name;}
		}
		public override Type ReflectedType {
			get {return typeb;}
		}

		public override object[] GetCustomAttributes(bool inherit) {
			return null;
		}
		public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
			return null;
		}
		public FieldToken GetToken() {
			return new FieldToken (0x04000000 | table_idx);
		}
		public override object GetValue(object obj) {
			return null;
		}
		public override bool IsDefined( Type attributeType, bool inherit) {
			return false;
		}
		internal void SetRVAData (byte[] data) {
			rva_data = (byte[])data.Clone ();
		}
		public void SetConstant( object defaultValue) {
			/*if (defaultValue.GetType() != type)
				throw new ArgumentException ("Constant doesn't match field type");*/
			def_value = defaultValue;
		}

		public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
			string attrname = customBuilder.Ctor.ReflectedType.FullName;
			if (attrname == "System.Runtime.InteropServices.FieldOffsetAttribute") {
				byte[] data = customBuilder.Data;
				offset = (int)data [2];
				offset |= ((int)data [3]) << 8;
				offset |= ((int)data [4]) << 16;
				offset |= ((int)data [5]) << 24;
				return;
			} else if (attrname == "System.NonSerializedAttribute") {
				attrs |= FieldAttributes.NotSerialized;
				return;
			} else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
				marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, true);
				/* FIXME: check for errors */
				return;
			}
			if (cattrs != null) {
				CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
				cattrs.CopyTo (new_array, 0);
				new_array [cattrs.Length] = customBuilder;
				cattrs = new_array;
			} else {
				cattrs = new CustomAttributeBuilder [1];
				cattrs [0] = customBuilder;
			}
		}

		public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
			SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
		}

		public void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
			marshal_info = unmanagedMarshal;
			attrs |= FieldAttributes.HasFieldMarshal;
		}

		public void SetOffset( int iOffset) {
			offset = iOffset;
		}
		public override void SetValue( object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture) {
		}

	}
}