Beispiel #1
0
        public static AndConstraint <ConstantNode> ShouldBeEnumNode(this QueryNode node, IEdmEnumType enumType, Int64 value)
        {
            node.Should().BeOfType <ConstantNode>();
            var enumNode = node.As <ConstantNode>();

            enumNode.TypeReference.ODataFullName().Should().Be(enumType.ODataFullName());
            ((ODataEnumValue)enumNode.Value).Value.Should().Be(value + "");
            ((ODataEnumValue)enumNode.Value).TypeName.Should().Be(enumType.ODataFullName());

            return(new AndConstraint <ConstantNode>(enumNode));
        }
Beispiel #2
0
        /// <summary>
        /// Parse string or integer to enum value
        /// </summary>
        /// <param name="enumType">edm enum type</param>
        /// <param name="value">input string value</param>
        /// <param name="enumValue">output edm enum value</param>
        /// <returns>true if parse succeeds, false if fails</returns>
        internal static bool TryParseEnum(IEdmEnumType enumType, string value, out ODataEnumValue enumValue)
        {
            long parsedValue;
            bool success = enumType.TryParseEnum(value, true, out parsedValue);
            enumValue = null;
            if (success)
            {
                // ODataEnumValue.Value will always be numeric string like '3', '10' instead of 'Cyan', 'Solid,Yellow', etc.
                // so user code can easily Enum.Parse() them into CLR value.
                enumValue = new ODataEnumValue(parsedValue.ToString(CultureInfo.InvariantCulture), enumType.ODataFullName());
            }

            return success;
        }
Beispiel #3
0
        /// <summary>
        /// Parse string or integer to enum value
        /// </summary>
        /// <param name="enumType">edm enum type</param>
        /// <param name="value">input string value</param>
        /// <param name="enumValue">output edm enum value</param>
        /// <returns>true if parse succeeds, false if fails</returns>
        internal static bool TryParseEnum(IEdmEnumType enumType, string value, out ODataEnumValue enumValue)
        {
            long parsedValue;
            bool success = enumType.TryParseEnum(value, true, out parsedValue);

            enumValue = null;
            if (success)
            {
                // ODataEnumValue.Value will always be numeric string like '3', '10' instead of 'Red', 'Solid,Yellow', etc.
                // so user code can easily Enum.Parse() them into CLR value.
                enumValue = new ODataEnumValue(parsedValue.ToString(CultureInfo.InvariantCulture), enumType.ODataFullName());
            }

            return(success);
        }