Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ILGenForCreateInstance() [2/2]

void System.Xml.Serialization.ReflectionAwareILGen.ILGenForCreateInstance ( CodeGenerator ilg,
Type type,
Type cast,
bool nonPublic )
inlinepackage

Definition at line 90 of file ReflectionAwareILGen.cs.

91 {
92 if (type == typeof(DBNull))
93 {
94 FieldInfo field = type.GetField("Value", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
95 ilg.LoadMember(field);
96 return;
97 }
98 if (type.FullName == "System.Xml.Linq.XElement")
99 {
100 Type type2 = type.Assembly.GetType("System.Xml.Linq.XName");
101 if (type2 != null)
102 {
103 MethodInfo method = type2.GetMethod("op_Implicit", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(string) });
104 ConstructorInfo constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { type2 });
105 if (method != null && constructor != null)
106 {
107 ilg.Ldstr("default");
108 ilg.Call(method);
109 ilg.New(constructor);
110 return;
111 }
112 }
113 }
114 Label label = ilg.DefineLabel();
115 Label label2 = ilg.DefineLabel();
116 ilg.Ldc(type);
117 MethodInfo method2 = typeof(IntrospectionExtensions).GetMethod("GetTypeInfo", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(Type) });
118 ilg.Call(method2);
119 LocalBuilder localBuilder = ilg.DeclareLocal(typeof(IEnumerator<>).MakeGenericType(typeof(ConstructorInfo)), "e");
120 MethodInfo method3 = typeof(TypeInfo).GetMethod("get_DeclaredConstructors");
121 MethodInfo method4 = typeof(IEnumerable<>).MakeGenericType(typeof(ConstructorInfo)).GetMethod("GetEnumerator");
122 ilg.Call(method3);
123 ilg.Call(method4);
124 ilg.Stloc(localBuilder);
125 ilg.WhileBegin();
126 MethodInfo method5 = typeof(IEnumerator).GetMethod("get_Current");
127 ilg.Ldloc(localBuilder);
128 ilg.Call(method5);
129 LocalBuilder localBuilder2 = ilg.DeclareLocal(typeof(ConstructorInfo), "constructorInfo");
130 ilg.Stloc(localBuilder2);
131 ilg.Ldloc(localBuilder2);
132 MethodInfo method6 = typeof(ConstructorInfo).GetMethod("get_IsStatic");
133 ilg.Call(method6);
134 ilg.Brtrue(label2);
135 ilg.Ldloc(localBuilder2);
136 MethodInfo method7 = typeof(ConstructorInfo).GetMethod("GetParameters");
137 ilg.Call(method7);
138 ilg.Ldlen();
139 ilg.Ldc(0);
140 ilg.Cne();
141 ilg.Brtrue(label2);
142 MethodInfo method8 = typeof(ConstructorInfo).GetMethod("Invoke", new Type[1] { typeof(object[]) });
143 ilg.Ldloc(localBuilder2);
144 ilg.Load(null);
145 ilg.Call(method8);
146 ilg.Br(label);
147 ilg.MarkLabel(label2);
148 ilg.WhileBeginCondition();
149 MethodInfo method9 = typeof(IEnumerator).GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
150 ilg.Ldloc(localBuilder);
151 ilg.Call(method9);
152 ilg.WhileEndCondition();
153 ilg.WhileEnd();
154 MethodInfo method10 = typeof(Activator).GetMethod("CreateInstance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(Type) });
155 ilg.Ldc(type);
156 ilg.Call(method10);
157 ilg.MarkLabel(label);
158 if (cast != null)
159 {
160 ilg.ConvertValue(method10.ReturnType, cast);
161 }
162 }

References System.Xml.Serialization.CodeGenerator.Br(), System.Xml.Serialization.CodeGenerator.Brtrue(), System.Xml.Serialization.CodeGenerator.Call(), System.Xml.Serialization.CodeGenerator.Cne(), System.Xml.Serialization.CodeGenerator.ConvertValue(), System.Xml.Serialization.CodeGenerator.DeclareLocal(), System.Xml.Serialization.CodeGenerator.DefineLabel(), System.Xml.Dictionary, System.Type.EmptyTypes, System.Xml.Serialization.CodeGenerator.Ldc(), System.Xml.Serialization.CodeGenerator.Ldlen(), System.Xml.Serialization.CodeGenerator.Ldloc(), System.Xml.Serialization.CodeGenerator.Ldstr(), System.Xml.Serialization.CodeGenerator.Load(), System.Xml.Serialization.CodeGenerator.LoadMember(), System.Xml.Serialization.CodeGenerator.MarkLabel(), System.Xml.Serialization.CodeGenerator.New(), System.Xml.Serialization.CodeGenerator.Stloc(), System.type, System.Xml.Serialization.CodeGenerator.WhileBegin(), System.Xml.Serialization.CodeGenerator.WhileBeginCondition(), System.Xml.Serialization.CodeGenerator.WhileEnd(), and System.Xml.Serialization.CodeGenerator.WhileEndCondition().