Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AssemblyGen.cs
Go to the documentation of this file.
5using System.Text;
7
9
10internal sealed class AssemblyGen
11{
12 private static AssemblyGen s_assembly;
13
14 private readonly ModuleBuilder _myModule;
15
16 private int _index;
17
18 private static AssemblyGen Assembly
19 {
20 get
21 {
22 if (s_assembly == null)
23 {
25 }
26 return s_assembly;
27 }
28 }
29
30 private AssemblyGen()
31 {
32 AssemblyName assemblyName = new AssemblyName("Snippets");
34 _myModule = assemblyBuilder.DefineDynamicModule(assemblyName.Name);
35 }
36
37 private TypeBuilder DefineType(string name, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type parent, TypeAttributes attr)
38 {
39 ContractUtils.RequiresNotNull(name, "name");
40 ContractUtils.RequiresNotNull(parent, "parent");
41 StringBuilder stringBuilder = new StringBuilder(name);
43 stringBuilder.Append('$');
44 stringBuilder.Append(value);
45 stringBuilder.Replace('+', '_').Replace('[', '_').Replace(']', '_')
46 .Replace('*', '_')
47 .Replace('&', '_')
48 .Replace(',', '_')
49 .Replace('\\', '_');
50 name = stringBuilder.ToString();
51 return _myModule.DefineType(name, attr, parent);
52 }
53
54 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "MulticastDelegate has a ctor with RequiresUnreferencedCode, but the generated derived type doesn't reference this ctor, so this is trim compatible.")]
55 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers", Justification = "MulticastDelegate and Delegate have multiple methods with DynamicallyAccessedMembers annotations. But the generated codein this case will not call any of them (it only defines a .ctor and Invoke method both of which are runtime implemented.")]
56 internal static TypeBuilder DefineDelegateType(string name)
57 {
58 return Assembly.DefineType(name, typeof(MulticastDelegate), TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.AutoClass);
59 }
60}
static void RequiresNotNull(object value, string paramName)
TypeBuilder DefineType(string name, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type parent, TypeAttributes attr)
static TypeBuilder DefineDelegateType(string name)
static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
ModuleBuilder DefineDynamicModule(string name)
TypeBuilder DefineType(string name)
override string ToString()
StringBuilder Append(char value, int repeatCount)
StringBuilder Replace(string oldValue, string? newValue)
static int CompareExchange(ref int location1, int value, int comparand)
static int Increment(ref int location)