diff options
author | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2018-10-05 10:04:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-05 10:04:05 +0200 |
commit | cf534be6d35979d25e688dbf8b85ed5c999e382d (patch) | |
tree | 885b957f25fed9059b61ba29ff7816e938e93fb9 /src/csharp | |
parent | 8df5b613f246ee743aa2f539f89ea44336539102 (diff) | |
parent | e88a40ae265ee82073ef9238a0289e6e952557a8 (diff) |
Merge pull request #16756 from jtattermusch/csharp_channeloptions_improvements
C#: ChannelOption improvements
Diffstat (limited to 'src/csharp')
-rw-r--r-- | src/csharp/Grpc.Core/ChannelOptions.cs | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/src/csharp/Grpc.Core/ChannelOptions.cs b/src/csharp/Grpc.Core/ChannelOptions.cs index 6ad5d56cad..880f2bef5f 100644 --- a/src/csharp/Grpc.Core/ChannelOptions.cs +++ b/src/csharp/Grpc.Core/ChannelOptions.cs @@ -26,8 +26,10 @@ namespace Grpc.Core /// <summary> /// Channel option specified when creating a channel. /// Corresponds to grpc_channel_args from grpc/grpc.h. + /// Commonly used channel option names are defined in <c>ChannelOptions</c>, + /// but any of the GRPC_ARG_* channel options names defined in grpc_types.h can be used. /// </summary> - public sealed class ChannelOption + public sealed class ChannelOption : IEquatable<ChannelOption> { /// <summary> /// Type of <c>ChannelOption</c>. @@ -119,10 +121,60 @@ namespace Grpc.Core return stringValue; } } + + /// <summary> + /// Determines whether the specified object is equal to the current object. + /// </summary> + public override bool Equals(object obj) + { + return Equals(obj as ChannelOption); + } + + /// <summary> + /// Determines whether the specified object is equal to the current object. + /// </summary> + public bool Equals(ChannelOption other) + { + return other != null && + type == other.type && + name == other.name && + intValue == other.intValue && + stringValue == other.stringValue; + } + + /// <summary> + /// A hash code for the current object. + /// </summary> + public override int GetHashCode() + { + var hashCode = 1412678443; + hashCode = hashCode * -1521134295 + type.GetHashCode(); + hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(name); + hashCode = hashCode * -1521134295 + intValue.GetHashCode(); + hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(stringValue); + return hashCode; + } + + /// <summary> + /// Equality operator. + /// </summary> + public static bool operator ==(ChannelOption option1, ChannelOption option2) + { + return EqualityComparer<ChannelOption>.Default.Equals(option1, option2); + } + + /// <summary> + /// Inequality operator. + /// </summary> + public static bool operator !=(ChannelOption option1, ChannelOption option2) + { + return !(option1 == option2); + } } /// <summary> - /// Defines names of supported channel options. + /// Defines names of most commonly used channel options. + /// Other supported options names can be found in grpc_types.h (GRPC_ARG_* definitions) /// </summary> public static class ChannelOptions { |