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

◆ TryEmitConstant()

static bool System.Linq.Expressions.Compiler.ILGen.TryEmitConstant ( this ILGenerator il,
object value,
Type type,
ILocalCache locals )
inlinestaticpackage

Definition at line 317 of file ILGen.cs.

318 {
319 if (value == null)
320 {
321 il.EmitDefault(type, locals);
322 return true;
323 }
324 if (il.TryEmitILConstant(value, type))
325 {
326 return true;
327 }
328 if (value is Type type2)
329 {
330 if (ShouldLdtoken(type2))
331 {
332 il.EmitType(type2);
333 if (type != typeof(Type))
334 {
335 il.Emit(OpCodes.Castclass, type);
336 }
337 return true;
338 }
339 return false;
340 }
341 if (value is MethodBase methodBase && ShouldLdtoken(methodBase))
342 {
343 il.Emit(OpCodes.Ldtoken, methodBase);
344 Type declaringType = methodBase.DeclaringType;
345 if (declaringType != null && declaringType.IsGenericType)
346 {
347 il.Emit(OpCodes.Ldtoken, declaringType);
348 il.Emit(OpCodes.Call, CachedReflectionInfo.MethodBase_GetMethodFromHandle_RuntimeMethodHandle_RuntimeTypeHandle);
349 }
350 else
351 {
352 il.Emit(OpCodes.Call, CachedReflectionInfo.MethodBase_GetMethodFromHandle_RuntimeMethodHandle);
353 }
354 if (type != typeof(MethodBase))
355 {
356 il.Emit(OpCodes.Castclass, type);
357 }
358 return true;
359 }
360 return false;
361 }
static bool ShouldLdtoken(Type t)
Definition ILGen.cs:363
static readonly OpCode Castclass
Definition OpCodes.cs:235
static readonly OpCode Ldtoken
Definition OpCodes.cs:353
static readonly OpCode Call
Definition OpCodes.cs:83

References System.Reflection.Emit.OpCodes.Call, System.Reflection.Emit.OpCodes.Castclass, System.Type.DeclaringType, System.Reflection.Emit.ILGenerator.Emit(), System.Type.IsGenericType, System.Reflection.Emit.OpCodes.Ldtoken, System.Linq.Expressions.CachedReflectionInfo.MethodBase_GetMethodFromHandle_RuntimeMethodHandle, System.Linq.Expressions.CachedReflectionInfo.MethodBase_GetMethodFromHandle_RuntimeMethodHandle_RuntimeTypeHandle, System.Linq.Expressions.Compiler.ILGen.ShouldLdtoken(), System.type, and System.value.