Ejemplo n.º 1
0
        // Translate the object of key in ODL path to string literal.
        private static string TranslateKeySegmentValue(object value, bool enableUriTemplateParsing)
        {
            if (value == null)
            {
                throw Error.ArgumentNull("value");
            }

            if (enableUriTemplateParsing)
            {
                Semantic.UriTemplateExpression uriTemplateExpression = value as Semantic.UriTemplateExpression;
                if (uriTemplateExpression != null)
                {
                    return(uriTemplateExpression.LiteralText);
                }
            }

            Semantic.ConstantNode constantNode = value as Semantic.ConstantNode;
            if (constantNode != null)
            {
                ODataEnumValue enumValue = constantNode.Value as ODataEnumValue;
                if (enumValue != null)
                {
                    return(ODataUriUtils.ConvertToUriLiteral(enumValue, ODataVersion.V4));
                }
            }

            return(ODataUriUtils.ConvertToUriLiteral(value, ODataVersion.V4));
        }
Ejemplo n.º 2
0
        // Translate the node in ODL path to string literal.
        private string TranslateNode(object node)
        {
            if (node == null)
            {
                throw Error.ArgumentNull("node");
            }

            Semantic.ConstantNode constantNode = node as Semantic.ConstantNode;
            if (constantNode != null)
            {
                if (_enableUriTemplateParsing)
                {
                    Semantic.UriTemplateExpression uriTemplateExpression = constantNode.Value as Semantic.UriTemplateExpression;
                    if (uriTemplateExpression != null)
                    {
                        return(uriTemplateExpression.LiteralText);
                    }
                }

                // Make the enum prefix free to work.
                ODataEnumValue enumValue = constantNode.Value as ODataEnumValue;
                if (enumValue != null)
                {
                    return(ODataUriUtils.ConvertToUriLiteral(enumValue, ODataVersion.V4));
                }

                return(constantNode.LiteralText);
            }

            Semantic.ConvertNode convertNode = node as Semantic.ConvertNode;
            if (convertNode != null)
            {
                return(TranslateNode(convertNode.Source));
            }

            Semantic.ParameterAliasNode parameterAliasNode = node as Semantic.ParameterAliasNode;
            if (parameterAliasNode != null)
            {
                return(TranslateParameterAlias(parameterAliasNode.Alias));
            }

            throw Error.NotSupported(
                      SRResources.CannotRecognizeNodeType,
                      typeof(ODataPathSegmentTranslator),
                      node.GetType().FullName);
        }