diff options
Diffstat (limited to 'src/csharp/Grpc.Core/ChannelArgs.cs')
-rw-r--r-- | src/csharp/Grpc.Core/ChannelArgs.cs | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/csharp/Grpc.Core/ChannelArgs.cs b/src/csharp/Grpc.Core/ChannelArgs.cs index 2d560c07b8..74ab310e44 100644 --- a/src/csharp/Grpc.Core/ChannelArgs.cs +++ b/src/csharp/Grpc.Core/ChannelArgs.cs @@ -30,6 +30,7 @@ #endregion using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -37,33 +38,18 @@ using Grpc.Core.Internal; namespace Grpc.Core { - // TODO: should we be using the builder pattern? + /// <summary> + /// gRPC channel options. + /// </summary> public class ChannelArgs { public const string SslTargetNameOverrideKey = "grpc.ssl_target_name_override"; - public class Builder - { - Dictionary<string, string> stringArgs = new Dictionary<string, string>(); - // TODO: AddInteger not supported yet. - public Builder AddString(string key, string value) - { - stringArgs.Add(key, value); - return this; - } + readonly ImmutableDictionary<string, string> stringArgs; - public ChannelArgs Build() - { - return new ChannelArgs(stringArgs); - } - } - - Dictionary<string, string> stringArgs; - - private ChannelArgs(Dictionary<string, string> stringArgs) + private ChannelArgs(ImmutableDictionary<string, string> stringArgs) { - // TODO: use immutable dict? - this.stringArgs = new Dictionary<string, string>(stringArgs); + this.stringArgs = stringArgs; } public string GetSslTargetNameOverride() @@ -76,11 +62,28 @@ namespace Grpc.Core return null; } - public static Builder NewBuilder() + public static Builder CreateBuilder() { return new Builder(); } + public class Builder + { + readonly Dictionary<string, string> stringArgs = new Dictionary<string, string>(); + + // TODO: AddInteger not supported yet. + public Builder AddString(string key, string value) + { + stringArgs.Add(key, value); + return this; + } + + public ChannelArgs Build() + { + return new ChannelArgs(stringArgs.ToImmutableDictionary()); + } + } + /// <summary> /// Creates native object for the channel arguments. /// </summary> |