| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- //
- // System.Reflection.Emit/FieldBuilder.cs
- //
- // Author:
- // Paolo Molaro ([email protected])
- //
- // (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;
- private RuntimeFieldHandle handle;
- 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) {
- }
- }
- }
|