本文整理汇总了C#中Smuxi.Engine.MessageBuilder.AppendFormat方法的典型用法代码示例。如果您正苦于以下问题:C# MessageBuilder.AppendFormat方法的具体用法?C# MessageBuilder.AppendFormat怎么用?C# MessageBuilder.AppendFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smuxi.Engine.MessageBuilder
的用法示例。
在下文中一共展示了MessageBuilder.AppendFormat方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendFormatNonIntegerBraceChaos
public void AppendFormatNonIntegerBraceChaos()
{
// "{{" -> escaped brace, verbatim text
// "{{" -> escaped brace, verbatim text
// "virtual " -> verbatim text
// "{" -> placeholder starts
// "0" -> placeholder text
// "}}" -> escaped brace, placeholder text
// "}}" -> escaped brace, placeholder text
// "}" -> placeholder ends
// => invalid placeholder name "0}}"
// (same behavior as String.Format)
var builder = new MessageBuilder();
builder.AppendFormat("{{{{virtual {0}}}}}", "hugs");
}
示例2: CommandWindow
private void CommandWindow(CommandModel cmd)
{
if (cmd.Parameter == "close") {
f_ChatViewManager.CurrentChat.Close();
return;
} else if (cmd.Parameter == "list") {
var thisChatView = f_MainWindow.ChatViewManager.GetChat(cmd.Chat);
for (int i = 0;; ++i) {
ChatView availableChatView = f_MainWindow.ChatViewManager.GetChat(i);
if (availableChatView == null) {
break;
}
var builder = new MessageBuilder();
builder.AppendEventPrefix();
builder.AppendFormat("{0} - {1}", i + 1, availableChatView.Name ?? "");
thisChatView.AddMessage(builder.ToMessage());
}
return;
}
int window;
if (!Int32.TryParse(cmd.Parameter, out window)) {
return;
}
ChatView chat = f_ChatViewManager.GetChat(window - 1);
if (chat == null) {
return;
}
f_ChatViewManager.CurrentChat = chat;
}
示例3: CommandBenchmarkMessageBuilder
public void CommandBenchmarkMessageBuilder(CommandModel cmd)
{
Trace.Call(cmd);
var count = 1000;
var showHelp = false;
var appendMessage = false;
var appendText = false;
var appendEvent = false;
var appendFormat = false;
var toMessage = false;
try {
var opts = new NDesk.Options.OptionSet() {
{ "c|count=", v => count = Int32.Parse(v) },
{ "m|append-message", v => appendMessage = true },
{ "t|append-text", v => appendText = true },
{ "e|append-event", v => appendEvent = true },
{ "f|append-format", v => appendFormat = true },
{ "T|to-message", v => toMessage = true },
};
opts.Add("h|?|help", x => {
showHelp = true;
var writer = new StringWriter();
opts.WriteOptionDescriptions(writer);
AddMessageToFrontend(
cmd,
CreateMessageBuilder().
AppendHeader("{0} usage", cmd.Command).
AppendText("\n").
AppendText("Parameters:\n").
AppendText(writer.ToString()).
ToMessage()
);
return;
});
opts.Parse(cmd.Parameter.Split(' '));
if (showHelp) {
return;
}
} catch (Exception ex) {
AddMessageToFrontend(
cmd,
CreateMessageBuilder().
AppendErrorText("Invalid parameter: {0}", ex.Message).
ToMessage()
);
return;
}
DateTime start, stop;
start = DateTime.UtcNow;
MessageBuilder builder;
for (var i = 0; i < count; i++) {
builder = new MessageBuilder();
if (appendMessage) {
builder.AppendMessage("This is message with a link to https://www.smuxi.org/.");
}
if (appendText) {
builder.AppendText("This is message with just text.");
}
if (appendEvent) {
builder.AppendEventPrefix();
}
if (appendFormat) {
builder.AppendFormat("{0} [{1}] has joined {2}",
"meebey3",
"[email protected]",
"#smuxi-devel");
}
if (toMessage) {
var msg = builder.ToMessage();
}
}
stop = DateTime.UtcNow;
builder = new MessageBuilder();
builder.AppendText("MessageBuilder().");
if (appendMessage) {
builder.AppendText("AppendMessage().");
}
if (appendText) {
builder.AppendText("AppendText().");
}
if (appendEvent) {
builder.AppendText("AppendEventPrefix().");
}
if (appendFormat) {
builder.AppendText("AppendFormat().");
}
if (toMessage) {
builder.AppendText("ToMessage()");
}
builder.AppendText(
" count: {1} took: {2:0} ms avg: {3:0.00} ms",
cmd.Data,
count,
(stop - start).TotalMilliseconds,
(stop - start).TotalMilliseconds / count
);
AddMessageToFrontend(cmd, builder.ToMessage());
//.........这里部分代码省略.........
示例4: AppendFormatWithBracedStrings
public void AppendFormatWithBracedStrings()
{
var builder = new MessageBuilder();
builder.TimeStamp = DateTime.MinValue;
builder.AppendText("{{virtual hugs}}");
var expectedMsg = builder.ToMessage();
builder = new MessageBuilder();
builder.TimeStamp = DateTime.MinValue;
builder.AppendFormat("{{{{{0} hugs}}}}", "virtual");
var actualMsg = builder.ToMessage();
Assert.AreEqual(expectedMsg, actualMsg);
}
示例5: AppendFormatPlaceholderOverflow
public void AppendFormatPlaceholderOverflow()
{
var builder = new MessageBuilder();
builder.AppendFormat("Hello, {1}!", "world");
}
示例6: AppendFormatNonIntegerPlaceholder
public void AppendFormatNonIntegerPlaceholder()
{
var builder = new MessageBuilder();
builder.AppendFormat("Hello, {zeroth}!", "world");
}
示例7: AppendFormatNegativePlaceholder
public void AppendFormatNegativePlaceholder()
{
var builder = new MessageBuilder();
builder.AppendFormat("Hello, {-1}!", "world");
}
示例8: AppendFormatMissingOpeningBrace
public void AppendFormatMissingOpeningBrace()
{
var builder = new MessageBuilder();
builder.AppendFormat("Hello, 0}!", "world");
}
示例9: AppendFormatWithSubmessage
public void AppendFormatWithSubmessage()
{
var builder = new MessageBuilder();
builder.TimeStamp = DateTime.MinValue;
builder.AppendText("I wonder if I can trick this bot to op me.");
var expectedMsg = builder.ToMessage();
builder = new MessageBuilder();
builder.TimeStamp = DateTime.MinValue;
builder.AppendText("op");
var insideMsg = builder.ToMessage();
builder = new MessageBuilder();
builder.TimeStamp = DateTime.MinValue;
builder.AppendFormat("I wonder if I can trick this bot to {0} me.", insideMsg);
var actualMsg = builder.ToMessage();
Assert.AreEqual(expectedMsg, actualMsg);
}
示例10: AppendFormatWithStrings
public void AppendFormatWithStrings()
{
var builder = new MessageBuilder();
builder.TimeStamp = DateTime.MinValue;
builder.AppendText("The quick brown fox jumps over the lazy dog.");
var expectedMsg = builder.ToMessage();
builder = new MessageBuilder();
builder.TimeStamp = DateTime.MinValue;
builder.AppendFormat("The quick brown {0} jumps over the lazy {1}.", "fox", "dog");
var actualMsg = builder.ToMessage();
Assert.AreEqual(expectedMsg, actualMsg);
}
示例11: AppendFormatWithoutPlaceholders
public void AppendFormatWithoutPlaceholders()
{
var builder = new MessageBuilder();
builder.TimeStamp = DateTime.MinValue;
builder.AppendText("I hope this works");
var expectedMsg = builder.ToMessage();
builder = new MessageBuilder();
builder.TimeStamp = DateTime.MinValue;
builder.AppendFormat("I hope this works");
var actualMsg = builder.ToMessage();
Assert.AreEqual(expectedMsg, actualMsg);
}