You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Microsoft.Toolkit.Mvvm.SourceGenerators/ComponentModel/ObservableValidatorValidateAllPropertiesGenerator.cs
+19-13Lines changed: 19 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,10 @@ public void Execute(GeneratorExecutionContext context)
69
69
// over the created delegate to be able to cache it as an Action<object> instance. This pattern enables the same
70
70
// functionality and with almost identical performance (not noticeable in this context anyway), but while preserving
71
71
// full runtime type safety (as a safe cast is used to validate the input argument), and with less reflection needed.
72
+
// Note that we're deliberately creating a new delegate instance here and not using code that could see the C# compiler
73
+
// create a static class to cache a reusable delegate, because each generated method will only be called at most once,
74
+
// as the returned delegate will be cached by the MVVM Toolkit itself. So this ensures the the produced code is minimal,
75
+
// and that there will be no unnecessary static fields and objects being created and possibly never collected.
72
76
// This code takes a class symbol and produces a compilation unit as follows:
73
77
//
74
78
// // Licensed to the .NET Foundation under one or more agreements.
@@ -90,12 +94,13 @@ public void Execute(GeneratorExecutionContext context)
90
94
// [global::System.Obsolete("This method is not intended to be called directly by user code")]
91
95
// public static global::System.Action<object> CreateAllPropertiesValidator(<INSTANCE_TYPE> _)
0 commit comments