예제 #1
0
        private static bool IsOpCodeSettingOutputParameterToDefaultValue(Instruction instruction)
        {
            if (instruction.Next.IsStindI()
                && instruction.IsLdcI()
                && instruction.GetLongValue() == 0L)
            {
                return true;
            }
            if (instruction.IsStindI()
                && instruction.Previous.IsLdcI()
                && instruction.Previous.GetLongValue() == 0L)
            {
                return true;
            }
            if (instruction.Next.IsStindR()
                && instruction.IsLdcR()
// ReSharper disable CompareOfFloatsByEqualityOperator
                && instruction.GetLongValue() == 0D)
// ReSharper restore CompareOfFloatsByEqualityOperator
            {
                return true;
            }
            if (instruction.IsStindR()
                && instruction.Previous.IsLdcR()
                // ReSharper disable CompareOfFloatsByEqualityOperator
                && instruction.Previous.GetLongValue() == 0D)
            // ReSharper restore CompareOfFloatsByEqualityOperator
            {
                return true;
            }
            if (instruction.OpCode == OpCodes.Ldnull
                && instruction.Next.OpCode == OpCodes.Stind_Ref)
            {
                return true;
            }
            if (instruction.Next.OpCode == OpCodes.Ldnull
                && instruction.Next.Next.OpCode == OpCodes.Stind_Ref)
            {
                return true;
            }
            if (instruction.OpCode == OpCodes.Stind_Ref
                && instruction.Previous.OpCode == OpCodes.Ldnull)
            {
                return true;
            }
            return false;
        }
예제 #2
0
        private static bool IsOpCodeSettingLocalVariableToDefaultValue(Instruction instruction)
        {
            if (instruction.Next.OpCode == OpCodes.Stloc
                && instruction.IsLdcI()
                && instruction.GetLongValue() == 0L)
            {
                return true;
            }
            if (instruction.OpCode == OpCodes.Stloc
                && instruction.Previous.IsLdcI()
                && instruction.Previous.GetLongValue() == 0L)
            {
                return true;
            }
            if (instruction.Next.OpCode == OpCodes.Stloc
                && instruction.IsLdcR()
// ReSharper disable CompareOfFloatsByEqualityOperator
                && instruction.GetDoubleValue() == 0D)
// ReSharper restore CompareOfFloatsByEqualityOperator
            {
                return true;
            }
            if (instruction.OpCode == OpCodes.Stloc
                && instruction.Previous.IsLdcR()
// ReSharper disable CompareOfFloatsByEqualityOperator
                && instruction.Previous.GetDoubleValue() == 0D)
// ReSharper restore CompareOfFloatsByEqualityOperator
            {
                return true;
            }
            if (instruction.OpCode == OpCodes.Stobj
                && instruction.Previous.OpCode == OpCodes.Ldnull
                && instruction.Previous.Previous.OpCode == OpCodes.Ldloca)
            {
                return true;
            }
            return false;
        }