在 LINQPad 中,结果具有 NULL 的特殊样式。如何将其应用于布尔值或其他值?

发布于 2024-12-12 10:43:37 字数 164 浏览 2 评论 0原文

我希望能够设计不同的返回值,类似于 LINQPad 将 NULL 设计为斜体绿色文本的方式。具体来说,我想以不同的方式设置布尔值 TRUE 和 FALSE 的样式,例如蓝色和红色。

空值的样式不同

I would like to be able to style different return values similar to how LINQPad styles NULL as italic green text. Specifically, I would like to style Boolean values TRUE and FALSE differently like blue and red.

null values are styled differently

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明明#如月 2024-12-19 10:43:37

这无法通过内置样式表编辑器来完成。但是,您可以编写一个调用的扩展方法,如下所示:

void Main()
{
    // AdventureWorks
    Contacts.Select (c => new { c.FirstName, c.LastName, NameStyle = c.NameStyle.RedBlue() }).Dump();
}

static class Extensions
{
    public static object RedBlue (this bool value)
    {       
        string c = value ? "Blue" : "Red";
        return Util.RawHtml ("<span style='color:" + c + "'>" + value + "</span>");
    }
}

如果将扩展方法放入 VS 项目并将 DLL 复制到 LINQPad 插件文件夹中,它将自动可供所有查询使用。

编辑:您现在可以在“我的扩展”查询中定义该方法,而不必在 VS 中创建项目。

This can't be done through the built-in stylesheet editor. However you could write an extension method that you invoke as follows:

void Main()
{
    // AdventureWorks
    Contacts.Select (c => new { c.FirstName, c.LastName, NameStyle = c.NameStyle.RedBlue() }).Dump();
}

static class Extensions
{
    public static object RedBlue (this bool value)
    {       
        string c = value ? "Blue" : "Red";
        return Util.RawHtml ("<span style='color:" + c + "'>" + value + "</span>");
    }
}

If you put the extension method into a VS project and copy the DLL into the LINQPad plugins folder, it will be automatically available to all queries.

EDIT: You can now define that method in the 'My Extensions' query rather than having to create a project in VS.

三寸金莲 2024-12-19 10:43:37

我在 MyExtensions 草图中成功使用了以下代码块:

void Main()
{
    (!(true.Dump())).Dump();
}

public static class MyExtensions
{
    public static bool Dump (this bool value)
    {       
        string c = value ? "Blue" : "Red";
        Util.RawHtml ("<span style='color:" + c + "'>" + value + "</span>").Dump();
        return value;
    }
}

I have success with this code block in MyExtensions sketch:

void Main()
{
    (!(true.Dump())).Dump();
}

public static class MyExtensions
{
    public static bool Dump (this bool value)
    {       
        string c = value ? "Blue" : "Red";
        Util.RawHtml ("<span style='color:" + c + "'>" + value + "</span>").Dump();
        return value;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文