-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new SendMessage method overload without payload type
- Loading branch information
Ahmad Noman Musleh
committed
Jan 17, 2022
1 parent
26fb7d2
commit ea057a7
Showing
4 changed files
with
70 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Google.Protobuf; | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace OpenAPI.Net.Helpers | ||
{ | ||
public static class MessagePayloadTypeExtension | ||
{ | ||
/// <summary> | ||
/// This method returns the payload type of a message | ||
/// </summary> | ||
/// <typeparam name="T">IMessage</typeparam> | ||
/// <param name="message">The message</param> | ||
/// <returns>uint (Payload Type)</returns> | ||
/// <exception cref="InvalidOperationException"></exception> | ||
public static uint GetPayloadType<T>(this T message) where T : IMessage | ||
{ | ||
PropertyInfo property; | ||
|
||
try | ||
{ | ||
property = message.GetType().GetProperty("PayloadType"); | ||
} | ||
catch (Exception ex) when (ex is AmbiguousMatchException || ex is ArgumentNullException) | ||
{ | ||
throw new InvalidOperationException($"Couldn't get the PayloadType of the message {message}", ex); | ||
} | ||
|
||
return (uint)property.GetValue(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters