diff options
Diffstat (limited to 'csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs')
-rwxr-xr-x[-rw-r--r--] | csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs index df1292dc..4b0670f6 100644..100755 --- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs @@ -33,6 +33,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; @@ -51,25 +52,30 @@ namespace Google.Protobuf.WellKnownTypes /// </remarks> /// <param name="paths">Paths in the field mask</param> /// <param name="diagnosticOnly">Determines the handling of non-normalized values</param> - /// <exception cref="InvalidOperationException">The represented duration is invalid, and <paramref name="diagnosticOnly"/> is <c>false</c>.</exception> + /// <exception cref="InvalidOperationException">The represented field mask is invalid, and <paramref name="diagnosticOnly"/> is <c>false</c>.</exception> internal static string ToJson(IList<string> paths, bool diagnosticOnly) { var firstInvalid = paths.FirstOrDefault(p => !ValidatePath(p)); if (firstInvalid == null) { - var builder = new StringBuilder(); - JsonFormatter.WriteString(builder, string.Join(",", paths.Select(JsonFormatter.ToCamelCase))); - return builder.ToString(); + var writer = new StringWriter(); +#if NET35 + var query = paths.Select(JsonFormatter.ToJsonName); + JsonFormatter.WriteString(writer, string.Join(",", query.ToArray())); +#else + JsonFormatter.WriteString(writer, string.Join(",", paths.Select(JsonFormatter.ToJsonName))); +#endif + return writer.ToString(); } else { if (diagnosticOnly) { - var builder = new StringBuilder(); - builder.Append("{ \"@warning\": \"Invalid FieldMask\", \"paths\": "); - JsonFormatter.Default.WriteList(builder, (IList) paths); - builder.Append(" }"); - return builder.ToString(); + var writer = new StringWriter(); + writer.Write("{ \"@warning\": \"Invalid FieldMask\", \"paths\": "); + JsonFormatter.Default.WriteList(writer, (IList)paths); + writer.Write(" }"); + return writer.ToString(); } else { @@ -79,9 +85,9 @@ namespace Google.Protobuf.WellKnownTypes } /// <summary> - /// Camel-case converter with added strictness for field mask formatting. + /// Checks whether the given path is valid for a field mask. /// </summary> - /// <exception cref="InvalidOperationException">The field mask is invalid for JSON representation</exception> + /// <returns>true if the path is valid; false otherwise</returns> private static bool ValidatePath(string input) { for (int i = 0; i < input.Length; i++) |