是否可以在DebuggerDisplay中使用条件? [英] Is it possible to use conditions in a DebuggerDisplay?

查看:99
本文介绍了是否可以在DebuggerDisplay中使用条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下类:

[DebuggerDisplay("{GetType().Name,nq}: FileName = {FileName,nq}")]
public class FileWrapper
{
    public string FileName { get; set; }
    public bool IsTempFile { get; set; }
    public string TempFileName { get; set; }
}

我想基于<$ c $添加调试器显示c> IsTempFileName 属性。当实例是临时文件时,我想添加字符串,TempFileName = {TempFileName,nq} 。我将如何实现这一目标?

I would like to add a debugger display based on the IsTempFileName property. I would like to add the string , TempFileName = {TempFileName,nq} when the instance is a temp file. How would I achieve something this?

推荐答案

您可以使用条件运算符(?:)

[DebuggerDisplay("{GetType().Name,nq}: FileName = {FileName,nq}{IsTempFile ? \", TempFileName: \" + TempFileName : System.String.Empty,nq}")]







IsTempFile == false

IsTempFile == true

这篇关于是否可以在DebuggerDisplay中使用条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆