// 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); }
/// <summary> /// Translate parameter alias node to corresponding single value node. /// </summary> /// <param name="node">The node to be translated.</param> /// <param name="parameterAliasNodes">The parameter alias node mapping.</param> /// <returns>The translated node.</returns> public static Semantic.SingleValueNode TranslateParameterAlias( Semantic.SingleValueNode node, IDictionary <string, Semantic.SingleValueNode> parameterAliasNodes) { if (node == null) { throw Error.ArgumentNull("node"); } if (parameterAliasNodes == null) { throw Error.ArgumentNull("parameterAliasNodes"); } Semantic.ParameterAliasNode parameterAliasNode = node as Semantic.ParameterAliasNode; if (parameterAliasNode == null) { return(node); } Semantic.SingleValueNode singleValueNode; if (parameterAliasNodes.TryGetValue(parameterAliasNode.Alias, out singleValueNode) && singleValueNode != null) { if (singleValueNode is Semantic.ParameterAliasNode) { singleValueNode = TranslateParameterAlias(singleValueNode, parameterAliasNodes); } return(singleValueNode); } // Parameter alias value is assumed to be null if it is not found. // Do not need to translate the parameter alias node from the query string // because this method only deals with the parameter alias node mapping from ODL parser. return(null); }