コード例 #1
0
        public static UnaryOperatorKind WithOverflowChecksIfApplicable(this UnaryOperatorKind kind, bool enabled)
        {
            if (enabled)
            {
                // If it's dynamic and we're in a checked context then just mark it as checked,
                // regardless of whether it is +x -x !x ~x ++x --x x++ or x--. Let the lowering
                // pass sort out what to do with it.

                if (kind.IsDynamic())
                {
                    return(kind | UnaryOperatorKind.Checked);
                }

                if (kind.IsIntegral())
                {
                    switch (kind.Operator())
                    {
                    case UnaryOperatorKind.PrefixIncrement:
                    case UnaryOperatorKind.PostfixIncrement:
                    case UnaryOperatorKind.PrefixDecrement:
                    case UnaryOperatorKind.PostfixDecrement:
                    case UnaryOperatorKind.UnaryMinus:
                        return(kind | UnaryOperatorKind.Checked);
                    }
                }
                return(kind);
            }
            else
            {
                return(kind & ~UnaryOperatorKind.Checked);
            }
        }