/// <summary> /// Write the query token as URI part to this builder. /// </summary> /// <param name="query">To write as URI part.</param> protected internal void WriteQuery(QueryToken query) { ExceptionUtils.CheckArgumentNotNull(query, "query"); switch (query.Kind) { case QueryTokenKind.BinaryOperator: this.WriteBinary((BinaryOperatorQueryToken)query); break; case QueryTokenKind.FunctionCall: this.WriteFunctionCall((FunctionCallQueryToken)query); break; case QueryTokenKind.Literal: this.WriteLiteral((LiteralQueryToken)query); break; case QueryTokenKind.PropertyAccess: this.WritePropertyAccess((PropertyAccessQueryToken)query); break; case QueryTokenKind.NonRootSegment: this.WriteNavigationProperty((NavigationPropertyToken)query); break; case QueryTokenKind.Star: this.WriteStar((StarQueryToken)query); break; case QueryTokenKind.UnaryOperator: this.WriteUnary((UnaryOperatorQueryToken)query); break; case QueryTokenKind.KeywordSegment: case QueryTokenKind.Segment: this.WriteSegment((SegmentQueryToken)query); break; case QueryTokenKind.OrderBy: this.WriteOrderBy((OrderByQueryToken)query); break; case QueryTokenKind.QueryOption: this.WriteQueryOption((QueryOptionQueryToken)query); break; case QueryTokenKind.Select: this.WriteSelect((SelectQueryToken)query); break; case QueryTokenKind.Extension: default: ODataUriBuilderUtils.NotSupported(query.Kind); break; } }
/// <summary> /// Write the query token as URI part to this builder. /// </summary> /// <param name="queryPart">To write as URI part.</param> internal void WriteQuery(QueryToken queryPart) { DebugUtils.CheckNoExternalCallers(); ExceptionUtils.CheckArgumentNotNull(queryPart, "query"); switch (queryPart.Kind) { case QueryTokenKind.BinaryOperator: this.WriteBinary((BinaryOperatorToken)queryPart); break; case QueryTokenKind.FunctionCall: this.WriteFunctionCall((FunctionCallToken)queryPart); break; case QueryTokenKind.Literal: this.WriteLiteral((LiteralToken)queryPart); break; case QueryTokenKind.EndPath: this.WritePropertyAccess((EndPathToken)queryPart); break; case QueryTokenKind.InnerPath: this.WriteNavigationProperty((InnerPathToken)queryPart); break; case QueryTokenKind.Star: this.WriteStar((StarToken)queryPart); break; case QueryTokenKind.UnaryOperator: this.WriteUnary((UnaryOperatorToken)queryPart); break; case QueryTokenKind.OrderBy: this.WriteOrderBy((OrderByToken)queryPart); break; case QueryTokenKind.CustomQueryOption: this.WriteQueryOption((CustomQueryOptionToken)queryPart); break; case QueryTokenKind.Select: this.WriteSelect((SelectToken)queryPart); break; default: ODataUriBuilderUtils.NotSupportedQueryTokenKind(queryPart.Kind); break; } }
/// <summary> /// Write the Uri string representation of the given CLR object literal to the given builder. /// </summary> /// <param name="builder">The <see cref="StringBuilder"/> to write the <paramref name="clrLiteral"/> to.</param> /// <param name="clrLiteral">The object to write as literal.</param> private static void WriteClrLiteral(StringBuilder builder, object clrLiteral) { if (clrLiteral == null) { builder.Append(ExpressionConstants.KeywordNull); return; } TypeCode code = Type.GetTypeCode(clrLiteral.GetType()); switch (code) { case TypeCode.Byte: builder.Append(((byte)clrLiteral).ToString(ODataUriBuilderUtils.IntegerFormat, CultureInfo.InvariantCulture)); return; case TypeCode.Boolean: builder.Append((bool)clrLiteral ? ExpressionConstants.KeywordTrue : ExpressionConstants.KeywordFalse); return; case TypeCode.DateTime: builder.Append(ExpressionConstants.LiteralPrefixDateTime); builder.Append(ExpressionConstants.SymbolSingleQuote); builder.Append(((DateTime)clrLiteral).ToString(ODataUriBuilderUtils.DateTimeFormat, CultureInfo.InvariantCulture)); builder.Append(ExpressionConstants.SymbolSingleQuote); return; case TypeCode.Decimal: builder.Append(((Decimal)clrLiteral).ToString(ODataUriBuilderUtils.DecimalFormatInfo)); builder.Append(ExpressionConstants.LiteralSuffixDecimal); return; case TypeCode.Double: builder.Append(((Double)clrLiteral).ToString(ODataUriBuilderUtils.DoubleFormat, ODataUriBuilderUtils.DoubleFormatInfo)); return; case TypeCode.Int16: builder.Append(((short)clrLiteral).ToString(ODataUriBuilderUtils.IntegerFormat, CultureInfo.InvariantCulture)); return; case TypeCode.Int32: builder.Append(((Int32)clrLiteral).ToString(ODataUriBuilderUtils.IntegerFormat, CultureInfo.InvariantCulture)); return; case TypeCode.Int64: builder.Append(((Int64)clrLiteral).ToString(ODataUriBuilderUtils.IntegerFormat, CultureInfo.InvariantCulture)); builder.Append(ExpressionConstants.LiteralSuffixInt64); return; case TypeCode.SByte: builder.Append(((SByte)clrLiteral).ToString(ODataUriBuilderUtils.IntegerFormat, CultureInfo.InvariantCulture)); return; case TypeCode.Single: builder.Append(((float)clrLiteral).ToString(ODataUriBuilderUtils.FloatFormat, CultureInfo.InvariantCulture)); builder.Append(ExpressionConstants.LiteralSuffixSingle); return; case TypeCode.String: builder.Append(ExpressionConstants.SymbolSingleQuote); builder.Append(Uri.EscapeDataString(ODataUriBuilderUtils.Escape(clrLiteral.ToString()))); builder.Append(ExpressionConstants.SymbolSingleQuote); return; default: break; } if (clrLiteral is DateTimeOffset) { builder.Append(ExpressionConstants.LiteralPrefixDateTimeOffset); builder.Append(ExpressionConstants.SymbolSingleQuote); builder.Append(((DateTimeOffset)clrLiteral).ToString(ODataUriBuilderUtils.DateTimeOffsetFormat, CultureInfo.InvariantCulture)); builder.Append(ExpressionConstants.SymbolSingleQuote); return; } if (clrLiteral is TimeSpan) { builder.Append(ExpressionConstants.LiteralPrefixTime); builder.Append(ExpressionConstants.SymbolSingleQuote); builder.Append(XmlConvert.ToString((TimeSpan)clrLiteral)); builder.Append(ExpressionConstants.SymbolSingleQuote); return; } if (clrLiteral is Guid) { builder.Append(ExpressionConstants.LiteralPrefixGuid); builder.Append(ExpressionConstants.SymbolSingleQuote); builder.Append(((Guid)clrLiteral).ToString(ODataUriBuilderUtils.IntegerFormat)); builder.Append(ExpressionConstants.SymbolSingleQuote); return; } byte[] bytes = clrLiteral as byte[]; if (bytes != null) { builder.Append(ExpressionConstants.LiteralPrefixBinary); builder.Append(ExpressionConstants.SymbolSingleQuote); foreach (byte @byte in bytes) { builder.Append(@byte.ToString(ODataUriBuilderUtils.BinaryFormat, CultureInfo.InvariantCulture)); } builder.Append(ExpressionConstants.SymbolSingleQuote); return; } Geography geography = clrLiteral as Geography; if (geography != null) { builder.Append(ExpressionConstants.LiteralPrefixGeography); builder.Append(ExpressionConstants.SymbolSingleQuote); builder.Append(LiteralUtils.ToWellKnownText(geography)); builder.Append(ExpressionConstants.SymbolSingleQuote); return; } Geometry geometry = clrLiteral as Geometry; if (geometry != null) { builder.Append(ExpressionConstants.LiteralPrefixGeometry); builder.Append(ExpressionConstants.SymbolSingleQuote); builder.Append(LiteralUtils.ToWellKnownText(geometry)); builder.Append(ExpressionConstants.SymbolSingleQuote); return; } ODataUriBuilderUtils.NotSupported(clrLiteral.GetType()); }