Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FieldBuilder.cs
Go to the documentation of this file.
3
5
6public sealed class FieldBuilder : FieldInfo
7{
8 private int m_fieldTok;
9
11
12 private string m_fieldName;
13
15
17
18 public override int MetadataToken => m_fieldTok;
19
20 public override Module Module => m_typeBuilder.Module;
21
22 public override string Name => m_fieldName;
23
24 public override Type? DeclaringType
25 {
26 get
27 {
29 {
30 return null;
31 }
32 return m_typeBuilder;
33 }
34 }
35
36 public override Type? ReflectedType
37 {
38 get
39 {
41 {
42 return null;
43 }
44 return m_typeBuilder;
45 }
46 }
47
48 public override Type FieldType => m_fieldType;
49
51 {
52 get
53 {
55 }
56 }
57
59
60 internal FieldBuilder(TypeBuilder typeBuilder, string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)
61 {
62 if (fieldName == null)
63 {
64 throw new ArgumentNullException("fieldName");
65 }
66 if (fieldName.Length == 0)
67 {
68 throw new ArgumentException(SR.Argument_EmptyName, "fieldName");
69 }
70 if (fieldName[0] == '\0')
71 {
72 throw new ArgumentException(SR.Argument_IllegalName, "fieldName");
73 }
74 if (type == null)
75 {
76 throw new ArgumentNullException("type");
77 }
78 if (type == typeof(void))
79 {
81 }
82 m_fieldName = fieldName;
83 m_typeBuilder = typeBuilder;
85 m_Attributes = attributes & ~FieldAttributes.ReservedMask;
87 fieldSigHelper.AddArgument(type, requiredCustomModifiers, optionalCustomModifiers);
88 int length;
89 byte[] signature = fieldSigHelper.InternalGetSignature(out length);
91 m_fieldTok = TypeBuilder.DefineField(new QCallModule(ref module), typeBuilder.TypeToken, fieldName, signature, length, m_Attributes);
92 }
93
94 internal void SetData(byte[] data, int size)
95 {
97 ModuleBuilder.SetFieldRVAContent(new QCallModule(ref module), m_fieldTok, data, size);
98 }
99
100 public override object? GetValue(object? obj)
101 {
103 }
104
105 public override void SetValue(object? obj, object? val, BindingFlags invokeAttr, Binder? binder, CultureInfo? culture)
106 {
108 }
109
110 public override object[] GetCustomAttributes(bool inherit)
111 {
113 }
114
115 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
116 {
118 }
119
120 public override bool IsDefined(Type attributeType, bool inherit)
121 {
123 }
124
125 public void SetOffset(int iOffset)
126 {
129 TypeBuilder.SetFieldLayoutOffset(new QCallModule(ref module), m_fieldTok, iOffset);
130 }
131
132 public void SetConstant(object? defaultValue)
133 {
135 if (defaultValue == null && m_fieldType.IsValueType && (!m_fieldType.IsGenericType || !(m_fieldType.GetGenericTypeDefinition() == typeof(Nullable<>))))
136 {
138 }
140 }
141
142 public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
143 {
144 if (con == null)
145 {
146 throw new ArgumentNullException("con");
147 }
148 if (binaryAttribute == null)
149 {
150 throw new ArgumentNullException("binaryAttribute");
151 }
152 ModuleBuilder moduleBuilder = m_typeBuilder.Module as ModuleBuilder;
154 TypeBuilder.DefineCustomAttribute(moduleBuilder, m_fieldTok, moduleBuilder.GetConstructorToken(con), binaryAttribute);
155 }
156
158 {
159 if (customBuilder == null)
160 {
161 throw new ArgumentNullException("customBuilder");
162 }
164 ModuleBuilder mod = m_typeBuilder.Module as ModuleBuilder;
165 customBuilder.CreateCustomAttribute(mod, m_fieldTok);
166 }
167}
void CreateCustomAttribute(ModuleBuilder mod, int tkOwner)
override FieldAttributes Attributes
override object[] GetCustomAttributes(bool inherit)
override? object GetValue(object? obj)
void SetData(byte[] data, int size)
void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
override object[] GetCustomAttributes(Type attributeType, bool inherit)
override RuntimeFieldHandle FieldHandle
override bool IsDefined(Type attributeType, bool inherit)
void SetConstant(object? defaultValue)
override void SetValue(object? obj, object? val, BindingFlags invokeAttr, Binder? binder, CultureInfo? culture)
FieldBuilder(TypeBuilder typeBuilder, string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)
void SetCustomAttribute(CustomAttributeBuilder customBuilder)
int GetConstructorToken(ConstructorInfo con)
static void SetFieldRVAContent(QCallModule module, int fdToken, byte[] data, int length)
byte[] InternalGetSignature(out int length)
static SignatureHelper GetFieldSigHelper(Module? mod)
static void SetFieldLayoutOffset(QCallModule module, int fdToken, int iOffset)
static void DefineCustomAttribute(QCallModule module, int tkAssociate, int tkConstructor, byte[] attr, int attrLength)
static int DefineField(QCallModule module, int tkParent, string name, byte[] signature, int sigLength, FieldAttributes attributes)
static unsafe void SetConstantValue(QCallModule module, int tk, int corType, void *pValue)
static string Argument_ConstantNull
Definition SR.cs:534
static string NotSupported_DynamicModule
Definition SR.cs:1672
static string Argument_IllegalName
Definition SR.cs:630
static string Argument_BadFieldType
Definition SR.cs:486
static string Argument_EmptyName
Definition SR.cs:584
Definition SR.cs:7
bool IsValueType
Definition Type.cs:234
virtual bool IsGenericType
Definition Type.cs:111
virtual Type GetGenericTypeDefinition()
Definition Type.cs:495