本文整理匯總了C#中System.Globalization.Message.ToJson方法的典型用法代碼示例。如果您正苦於以下問題:C# Message.ToJson方法的具體用法?C# Message.ToJson怎麽用?C# Message.ToJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Globalization.Message
的用法示例。
在下文中一共展示了Message.ToJson方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SendAsync
/// <summary>
/// Asynchronously sends the specified message.
/// </summary>
/// <param name="message">The message to send.</param>
/// <param name="cancellationToken">A token to monitor for cancellation requests. The default value is <see cref="System.Threading.CancellationToken.None"/>.</param>
/// <returns>The message.</returns>
public async Task SendAsync(Message message, CancellationToken cancellationToken = default(CancellationToken))
{
if (message == null) throw new ArgumentNullException("message");
if (_isDisposed) throw new ObjectDisposedException("Client");
if (ConnectionState != ClientConnectionState.Established) throw new InvalidOperationException("Client must be connected.");
var json = message.ToJson();
var response = await Http.PostJsonAsync("https://slack.com/api/chat.postMessage", json, cancellationToken, "token", _token);
if (response["ok"] != "true")
throw SlackException.FromStatusCode(response["error"]);
}