diff --git a/docs/Rules/MA0151.md b/docs/Rules/MA0151.md index 467ddaba9..4b8906b59 100644 --- a/docs/Rules/MA0151.md +++ b/docs/Rules/MA0151.md @@ -4,6 +4,7 @@ Source: [DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzer.cs](https Validates the expressions within `[DebuggerDisplay]` attributes to ensure they reference valid members. +The names are resolved in the type, then in its containing types and its containing namespaces. ````c# [DebuggerDisplay("{Display}")] // compliant diff --git a/src/Meziantou.Analyzer/Rules/DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzer.cs b/src/Meziantou.Analyzer/Rules/DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzer.cs index a03d1c970..2ef0e8f9b 100644 --- a/src/Meziantou.Analyzer/Rules/DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/DebuggerDisplayAttributeShouldContainValidExpressionsAnalyzer.cs @@ -200,7 +200,7 @@ private static bool IsValid(Compilation compilation, ISymbol rootSymbol, List value.ToString(); + } + } + """; + + return test.RunAsync(); + } + + [Fact] + public Task StaticMemberOfContainingType() + { + var test = CreateTest(); + test.TestCode = """ + using System.Diagnostics; + public class Outer + { + private static string Prefix => ""; + + [DebuggerDisplay("{Prefix.Length}")] + public class Dummy + { + } + } + """; + + return test.RunAsync(); + } + + [Fact] + public Task UnknownMemberOfContainingNamespace() + { + var test = CreateTest(); + test.TestCode = """ + using System.Diagnostics; + namespace N + { + [{|MA0151:DebuggerDisplay("{Helper.Unknown()}")|}] + public class Dummy + { + } + + public static class Helper + { + } + } + """; + + return test.RunAsync(); + } }