Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
IgnoreAccessChecksToAttributeBuilder.cs
Go to the documentation of this file.
1using System.Linq;
2
4
6{
8 {
9 TypeBuilder typeBuilder = mb.DefineType("System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute", TypeAttributes.Public, typeof(Attribute));
10 FieldBuilder fieldBuilder = typeBuilder.DefineField("assemblyName", typeof(string), FieldAttributes.Private);
11 ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, new Type[1] { fieldBuilder.FieldType });
12 ILGenerator iLGenerator = constructorBuilder.GetILGenerator();
13 iLGenerator.Emit(OpCodes.Ldarg_0);
14 iLGenerator.Emit(OpCodes.Ldarg, 1);
15 iLGenerator.Emit(OpCodes.Stfld, fieldBuilder);
16 iLGenerator.Emit(OpCodes.Ret);
17 PropertyBuilder propertyBuilder = typeBuilder.DefineProperty("AssemblyName", PropertyAttributes.None, CallingConventions.HasThis, typeof(string), null);
18 MethodBuilder methodBuilder = typeBuilder.DefineMethod("get_AssemblyName", MethodAttributes.Public, CallingConventions.HasThis, typeof(string), null);
19 propertyBuilder.SetGetMethod(methodBuilder);
20 iLGenerator = methodBuilder.GetILGenerator();
21 iLGenerator.Emit(OpCodes.Ldarg_0);
22 iLGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
23 iLGenerator.Emit(OpCodes.Ret);
24 TypeInfo typeInfo = typeof(AttributeUsageAttribute).GetTypeInfo();
25 ConstructorInfo con = typeInfo.DeclaredConstructors.Single((ConstructorInfo c) => c.GetParameters().Length == 1 && c.GetParameters()[0].ParameterType == typeof(AttributeTargets));
26 PropertyInfo propertyInfo = typeInfo.DeclaredProperties.Single((PropertyInfo f) => string.Equals(f.Name, "AllowMultiple"));
27 CustomAttributeBuilder customAttribute = new CustomAttributeBuilder(con, new object[1] { AttributeTargets.Assembly }, new PropertyInfo[1] { propertyInfo }, new object[1] { true });
28 typeBuilder.SetCustomAttribute(customAttribute);
29 return typeBuilder.CreateTypeInfo().DeclaredConstructors.Single();
30 }
31}
virtual void Emit(OpCode opcode)
TypeBuilder DefineType(string name)
static readonly OpCode Ldfld
Definition OpCodes.cs:245
static readonly OpCode Ret
Definition OpCodes.cs:87
static readonly OpCode Ldarg_0
Definition OpCodes.cs:9
static readonly OpCode Stfld
Definition OpCodes.cs:249
static readonly OpCode Ldarg
Definition OpCodes.cs:419
void SetGetMethod(MethodBuilder mdBuilder)
static int DefineMethod(QCallModule module, int tkParent, string name, byte[] signature, int sigLength, MethodAttributes attributes)
ConstructorBuilder DefineConstructor(MethodAttributes attributes, CallingConventions callingConvention, Type[]? parameterTypes)
static int DefineProperty(QCallModule module, int tkParent, string name, PropertyAttributes attributes, byte[] signature, int sigLength)
void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
static int DefineField(QCallModule module, int tkParent, string name, byte[] signature, int sigLength, FieldAttributes attributes)
ParameterInfo[] GetParameters()
TypeInfo IReflectableType. GetTypeInfo()
Definition TypeInfo.cs:101
virtual IEnumerable< PropertyInfo > DeclaredProperties
Definition TypeInfo.cs:84
virtual IEnumerable< ConstructorInfo > DeclaredConstructors
Definition TypeInfo.cs:21