C# 字符串格式化字典 Intellisense

C# String Formatting Dictionary Intellisense

我一直在尝试在下面的示例中将一些字符串加粗和斜体化,但它不起作用。是否可以编辑字符串的格式?

private TestQuickInfoSourceProvider m_provider;
    private ITextBuffer m_subjectBuffer;
    private Dictionary<string, string> m_dictionary;
    public TestQuickInfoSource(TestQuickInfoSourceProvider provider, ITextBuffer subjectBuffer)
    {
        m_provider = provider;
        m_subjectBuffer = subjectBuffer;

        //Methods and their description, good for unique keywords AKA QuickInfo words
        m_dictionary = new Dictionary<string, string>();
        m_dictionary.Add("adapt", "<b> Process given file </b>\n"

这是输出 http://i.stack.imgur.com/smDUF.png

格式化字符串的正确方法是什么?

编辑///

找到了一种更简单的方法来通过 CSV 处理大量数据。

代码的重要部分(未包含在 post 中)是 AugmentQuickInfoSession 方法的实现。我假设您目前只是 return 从您的 m_dictionary 那里获取字符串值。

在 QuickInfo 中获取格式化结果需要更多的工作。我们来看看AugmentQuickInfoSession的定义:

void AugmentQuickInfoSession(IQuickInfoSession existingQuickInfoSession, IList<object> quickInfoContent, out ITrackin)

quickInfoContentobject 的列表。如果你return一个String,它就不会被格式化。但是,如果您 return 一个 TextBlock 对象,则可以包含格式化文本。

示例代码:

var textBlock = new TextBlock { TextWrapping = TextWrapping.NoWrap };

var boldRun = new Run("This is a bit of bold text.");
boldRun.FontWeight = FontWeights.Bold;
textBlock.Inlines.Add(boldRun);

var normalRun = new Run("This is not very bold.);
textBlock.Inlines.Add(normalRun );

...

quickInfoContent.Add(textBlock);