コード例 #1
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;
        }