@@ -245,6 +245,37 @@ await VerifyAnalyzerAsync(
245245 . WithArguments ( "CreateDefaultStateViews" ) ) ;
246246 }
247247
248+ [ Fact ]
249+ public async Task VerifyErrorWhenDefaultValueCreatorMethodReturnsCreateDefaultValueDelegateThatReturnsAStaticInstance ( )
250+ {
251+ const string source =
252+ /* language=C#-test */
253+ //lang=csharp
254+ """
255+ #nullable enable
256+ #pragma warning disable MCTEXP001
257+ using System.Collections.Generic;
258+ using CommunityToolkit.Maui;
259+ using Microsoft.Maui.Controls;
260+
261+ namespace CommunityToolkit.Maui.UnitTests
262+ {
263+ [AttachedBindableProperty<IList<View>>("StateViews", DefaultValueCreatorMethodName = nameof(CreateStateViewsDelegate))]
264+ public static partial class TestContainer
265+ {
266+ static readonly BindableProperty.CreateDefaultValueDelegate CreateStateViewsDelegate = _ => StateViewList;
267+
268+ static List<View> StateViewList { get; } = [];
269+ }
270+ }
271+ """ ;
272+
273+ await VerifyAnalyzerAsync ( source ,
274+ Diagnostic ( )
275+ . WithSeverity ( DiagnosticSeverity . Warning )
276+ . WithArguments ( "CreateDefaultStateViews" ) ) ;
277+ }
278+
248279 [ Fact ]
249280 public async Task VerifyErrorWhenDefaultValueCreatorMethodReturnsStaticReadonlyPropertyFromDifferentClass ( )
250281 {
@@ -590,6 +621,32 @@ public static partial class TestContainer
590621 await VerifyAnalyzerAsync ( source ) ;
591622 }
592623
624+ [ Fact ]
625+ public async Task VerifyNoErrorWhenDefaultValueCreatorMethodReturnsCreateDefaultValueDelegateThatReturnsANewInstance ( )
626+ {
627+ const string source =
628+ /* language=C#-test */
629+ //lang=csharp
630+ """
631+ #nullable enable
632+ #pragma warning disable MCTEXP001
633+ using System.Collections.Generic;
634+ using CommunityToolkit.Maui;
635+ using Microsoft.Maui.Controls;
636+
637+ namespace CommunityToolkit.Maui.UnitTests
638+ {
639+ [AttachedBindableProperty<IList<View>>("StateViews", DefaultValueCreatorMethodName = nameof(CreateStateViewsDelegate))]
640+ public static partial class TestContainer
641+ {
642+ static readonly BindableProperty.CreateDefaultValueDelegate CreateStateViewsDelegate = (x) => new List<View>();
643+ }
644+ }
645+ """ ;
646+
647+ await VerifyAnalyzerAsync ( source ) ;
648+ }
649+
593650 static Task VerifyAnalyzerAsync ( string source , params IReadOnlyList < DiagnosticResult > expected )
594651 {
595652 return CSharpAnalyzerVerifier < BindablePropertyDefaultValueCreatorAnalyzer >
0 commit comments