Exemple #1
0
        private static ulong?GetConstantValueForBitwiseOrCheck(IOperation operation)
        {
            // We might have a nullable conversion on top of an integer constant. But only dig out
            // one level.

#if !CODE_STYLE
            if (operation is IConversionOperation conversion &&
                conversion.Conversion.IsImplicit &&
                conversion.Conversion.IsNullable)
            {
                operation = conversion.Operand;
            }
#endif

            var constantValue = operation.ConstantValue;
            if (!constantValue.HasValue || constantValue.Value == null)
            {
                return(null);
            }

            if (!operation.Type.SpecialType.IsIntegralType())
            {
                return(null);
            }

            return(IntegerUtilities.ToUInt64(constantValue.Value));
        }
        private static ExpressionSyntax GenerateIntegralLiteralExpression(
            ITypeSymbol type, object value, string suffix, bool canUseFieldReference)
        {
            // If it's the constant value 0, and the type of the value matches the type we want for
            // this context, then we can just emit the literal 0 here.  We don't want to emit things
            // like UInteger.MinValue.
            if (value != null && IntegerUtilities.ToUInt64(value) == 0 && TypesMatch(type, value))
            {
                return(GenerateLiteralExpression(0, "0"));
            }

            var constants = value.GetType().GetFields(BindingFlags.Public | BindingFlags.Static).Where(f => f.IsLiteral);

            return(GenerateLiteralExpression(type, value, constants, null, suffix, canUseFieldReference));
        }