@@ -95,10 +95,10 @@ public static void RegisterAll(this IMessenger messenger, object recipient)
95
95
ArgumentNullException . ThrowIfNull ( messenger ) ;
96
96
ArgumentNullException . ThrowIfNull ( recipient ) ;
97
97
98
- #pragma warning disable IL2026
99
98
// We use this method as a callback for the conditional weak table, which will handle
100
99
// thread-safety for us. This first callback will try to find a generated method for the
101
100
// target recipient type, and just invoke it to get the delegate to cache and use later.
101
+ [ RequiresUnreferencedCode ( "The type of the current instance cannot be statically discovered." ) ]
102
102
static Action < IMessenger , object > ? LoadRegistrationMethodsForType ( Type recipientType )
103
103
{
104
104
if ( recipientType . Assembly . GetType ( "CommunityToolkit.Mvvm.Messaging.__Internals.__IMessengerExtensions" ) is Type extensionsType &&
@@ -109,12 +109,11 @@ public static void RegisterAll(this IMessenger messenger, object recipient)
109
109
110
110
return null ;
111
111
}
112
- #pragma warning restore IL2026
113
112
114
113
// Try to get the cached delegate, if the generator has run correctly
115
114
Action < IMessenger , object > ? registrationAction = DiscoveredRecipients . RegistrationMethods . GetValue (
116
115
recipient . GetType ( ) ,
117
- static t => LoadRegistrationMethodsForType ( t ) ) ;
116
+ [ RequiresUnreferencedCode ( "The type of the current instance cannot be statically discovered." ) ] static ( t ) => LoadRegistrationMethodsForType ( t ) ) ;
118
117
119
118
if ( registrationAction is not null )
120
119
{
@@ -152,11 +151,11 @@ public static void RegisterAll<TToken>(this IMessenger messenger, object recipie
152
151
ArgumentNullException . ThrowIfNull ( recipient ) ;
153
152
ArgumentNullException . For < TToken > . ThrowIfNull ( token ) ;
154
153
155
- #pragma warning disable IL2026
156
154
// We use this method as a callback for the conditional weak table, which will handle
157
155
// thread-safety for us. This first callback will try to find a generated method for the
158
156
// target recipient type, and just invoke it to get the delegate to cache and use later.
159
157
// In this case we also need to create a generic instantiation of the target method first.
158
+ [ RequiresUnreferencedCode ( "The type of the current instance cannot be statically discovered." ) ]
160
159
static Action < IMessenger , object , TToken > LoadRegistrationMethodsForType ( Type recipientType )
161
160
{
162
161
if ( recipientType . Assembly . GetType ( "CommunityToolkit.Mvvm.Messaging.__Internals.__IMessengerExtensions" ) is Type extensionsType &&
@@ -224,7 +223,6 @@ from registrationMethod in registrationMethods
224
223
225
224
return Expression . Lambda < Action < IMessenger , object , TToken > > ( body , arg0 , arg1 , arg2 ) . Compile ( ) ;
226
225
}
227
- #pragma warning restore IL2026
228
226
229
227
// Get or compute the registration method for the current recipient type.
230
228
// As in CommunityToolkit.Diagnostics.TypeExtensions.ToTypeString, we use a lambda
@@ -233,7 +231,7 @@ from registrationMethod in registrationMethods
233
231
// For more info on this, see the related issue at https://github.com/dotnet/roslyn/issues/5835.
234
232
Action < IMessenger , object , TToken > registrationAction = DiscoveredRecipients < TToken > . RegistrationMethods . GetValue (
235
233
recipient . GetType ( ) ,
236
- static t => LoadRegistrationMethodsForType ( t ) ) ;
234
+ [ RequiresUnreferencedCode ( "The type of the current instance cannot be statically discovered." ) ] static ( t ) => LoadRegistrationMethodsForType ( t ) ) ;
237
235
238
236
// Invoke the cached delegate to actually execute the message registration
239
237
registrationAction ( messenger , recipient , token ) ;
0 commit comments