static void GenerateCompareTypeIL(DynamicMethodHelper il, Type t) { MethodInfo method = GetTypeMethod(t, TypeMethodType.Compare); if ((method == null) && (t.IsPrimitive == false)) { il.Pop(); il.Pop(); il.PushInt(1); return; } il.BeginScope(); { const string valX = "x"; const string valY = "y"; const string valThis = "_thisX"; const string trueLabel = "endTrue"; const string falseLabel = "endFalse"; const string endLabel = "endCheck"; il.DeclareLocal(valX, typeof(object)); il.PopLocal(valX); il.DeclareLocal(valY, typeof(object)); il.PopLocal(valY); // If both null or the same object then return true il.PushLocal(valX); il.PushLocal(valY); il.GotoIfEqual(trueLabel); // Exit false if either value is null il.PushLocal(valX); il.GotoIfFalse(falseLabel); il.PushLocal(valY); il.GotoIfFalse(falseLabel); // Both operands are non-null so call the type-specific comparison method if (t.IsPrimitive) { il.PushLocal(valX); il.UnboxValueType(t); il.PushLocal(valX); il.UnboxValueType(t); il.CompareEqual(); } else { Type paramType = method.GetParameters()[0].ParameterType; il.DebugWriteLine("Calling " + method); if (method.IsStatic) { il.PushLocal(valX); if (paramType.IsValueType) il.UnboxValueType(paramType); } else { il.DeclareLocal(valThis, t); il.PushLocal(valX); il.PopLocalFromObject(valThis); il.PushThis(valThis, method); } il.PushLocal(valY); if (paramType.IsValueType) il.UnboxValueType(paramType); il.CallMethod(method); } il.GotoIfFalse(falseLabel); il.MarkLabel(trueLabel); il.PushInt(1); il.Goto(endLabel); il.MarkLabel(falseLabel); il.DebugWriteLine("The following values are not equal:"); il.DebugWriteLocal(valX); il.DebugWriteLocal(valY); il.PushInt(0); il.MarkLabel(endLabel); } il.EndScope(); }