diff options
author | Jon Skeet <skeet@pobox.com> | 2015-10-07 17:08:25 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2015-10-07 17:08:25 +0100 |
commit | c34ed5c9bfd0577ccb00e259a8fc8f924a356819 (patch) | |
tree | 1e5b52e57900bbba566b31a58f7b0c1ecb1d9a54 /csharp/src/Google.Protobuf/Collections/MapField.cs | |
parent | 2842568f8d6759d34c0e48b428395851011597d2 (diff) | |
parent | 9ed6d4da3710daae65cdc60719ebff79a472b648 (diff) | |
download | protobuf-c34ed5c9bfd0577ccb00e259a8fc8f924a356819.tar.gz protobuf-c34ed5c9bfd0577ccb00e259a8fc8f924a356819.tar.bz2 protobuf-c34ed5c9bfd0577ccb00e259a8fc8f924a356819.zip |
Merge pull request #846 from jskeet/tostring
Support ToString in RepeatedField and MapField.
Diffstat (limited to 'csharp/src/Google.Protobuf/Collections/MapField.cs')
-rw-r--r-- | csharp/src/Google.Protobuf/Collections/MapField.cs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs index 0fa63bef..c0ed28ae 100644 --- a/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -35,6 +35,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Text; using Google.Protobuf.Compatibility; namespace Google.Protobuf.Collections @@ -45,10 +46,17 @@ namespace Google.Protobuf.Collections /// <typeparam name="TKey">Key type in the map. Must be a type supported by Protocol Buffer map keys.</typeparam> /// <typeparam name="TValue">Value type in the map. Must be a type supported by Protocol Buffers.</typeparam> /// <remarks> + /// <para> /// This implementation preserves insertion order for simplicity of testing /// code using maps fields. Overwriting an existing entry does not change the /// position of that entry within the map. Equality is not order-sensitive. /// For string keys, the equality comparison is provided by <see cref="StringComparer.Ordinal" />. + /// </para> + /// <para> + /// This implementation does not generally prohibit the use of key/value types which are not + /// supported by Protocol Buffers (e.g. using a key type of <code>byte</code>) but nor does it guarantee + /// that all operations will work in such cases. + /// </para> /// </remarks> public sealed class MapField<TKey, TValue> : IDeepCloneable<MapField<TKey, TValue>>, IDictionary<TKey, TValue>, IEquatable<MapField<TKey, TValue>>, IDictionary { @@ -482,6 +490,17 @@ namespace Google.Protobuf.Collections return size; } + /// <summary> + /// Returns a string representation of this repeated field, in the same + /// way as it would be represented by the default JSON formatter. + /// </summary> + public override string ToString() + { + var builder = new StringBuilder(); + JsonFormatter.Default.WriteDictionary(builder, this); + return builder.ToString(); + } + #region IDictionary explicit interface implementation void IDictionary.Add(object key, object value) { |