【问题标题】:How to change default message generated by Resharper for empty string check (null-check)如何更改 Resharper 生成的默认消息以进行空字符串检查(空检查)
【发布时间】:2019-11-03 10:14:49
【问题描述】:

Resharper 具有为参数添加空检查代码的强大功能。对于字符串,它可以添加string.IsNullOrWhiteSpace 检查ArgumentException。一切都很好,但我需要让 Resharper 生成另一条消息,而不是像默认情况下那样生成 Value cannot be null or whitespace。而不是这个,我想要Value cannot be null, empty, or consist only of white-space characters 消息。在Null checking 配置选项卡中,我没有找到与字符串检查相关的任何内容。还有其他地方可以配置消息吗?

【问题讨论】:

    标签: c# visual-studio resharper null-check


    【解决方案1】:

    当前的 ReSharper 版本 (2019.1.2) 似乎无法做到这一点。

    我检查了JetBrains.ReSharper.Intentions.CSharp.dllildasm,似乎字符串"Value cannot be null or whitespace.""Value cannot be null or empty." 是硬编码的,不能自定义。

    JetBrains.ReSharper.Intentions.CSharp.ContextActions.CheckParameters.StringParameterIsNotNullOrEmptyCheckActionget_ExceptionMessage方法:

    .method /*06001927*/ family hidebysig specialname virtual 
            instance string  get_ExceptionMessage() cil managed
    // SIG: 20 00 0E
    {
      // Method begins at RVA 0x82f24
      // Code size       6 (0x6)
      .maxstack  8
      IL_0000:  /* 72   | (70)017EBE       */ ldstr      "Value cannot be null or empty." /* 70017EBE */
      IL_0005:  /* 2A   |                  */ ret
    } // end of method StringParameterIsNotNullOrEmptyCheckAction::get_ExceptionMessage
    

    JetBrains.ReSharper.Intentions.CSharp.ContextActions.CheckParameters.StringParameterIsNotNullOrWhitespaceCheckActionget_ExceptionMessage方法:

    .method /*0600192D*/ family hidebysig specialname virtual 
            instance string  get_ExceptionMessage() cil managed
    // SIG: 20 00 0E
    {
      // Method begins at RVA 0x82f5f
      // Code size       6 (0x6)
      .maxstack  8
      IL_0000:  /* 72   | (70)017F4C       */ ldstr      "Value cannot be null or whitespace." /* 70017F4C */
      IL_0005:  /* 2A   |                  */ ret
    } // end of method StringParameterIsNotNullOrWhitespaceCheckAction::get_ExceptionMessage
    

    如果此功能对您很重要,那么您可以尝试通过在 JetBrains 的错误跟踪器中提交工单来请求它:https://youtrack.jetbrains.com

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 2017-11-25
    相关资源
    最近更新 更多