@@ -95,10 +95,10 @@ public static void RegisterAll(this IMessenger messenger, object recipient)
9595 ArgumentNullException . ThrowIfNull ( messenger ) ;
9696 ArgumentNullException . ThrowIfNull ( recipient ) ;
9797
98- #pragma warning disable IL2026
9998 // We use this method as a callback for the conditional weak table, which will handle
10099 // thread-safety for us. This first callback will try to find a generated method for the
101100 // 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." ) ]
102102 static Action < IMessenger , object > ? LoadRegistrationMethodsForType ( Type recipientType )
103103 {
104104 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)
109109
110110 return null ;
111111 }
112- #pragma warning restore IL2026
113112
114113 // Try to get the cached delegate, if the generator has run correctly
115114 Action < IMessenger , object > ? registrationAction = DiscoveredRecipients . RegistrationMethods . GetValue (
116115 recipient . GetType ( ) ,
117- static t => LoadRegistrationMethodsForType ( t ) ) ;
116+ [ RequiresUnreferencedCode ( "The type of the current instance cannot be statically discovered." ) ] static ( t ) => LoadRegistrationMethodsForType ( t ) ) ;
118117
119118 if ( registrationAction is not null )
120119 {
@@ -152,11 +151,11 @@ public static void RegisterAll<TToken>(this IMessenger messenger, object recipie
152151 ArgumentNullException . ThrowIfNull ( recipient ) ;
153152 ArgumentNullException . For < TToken > . ThrowIfNull ( token ) ;
154153
155- #pragma warning disable IL2026
156154 // We use this method as a callback for the conditional weak table, which will handle
157155 // thread-safety for us. This first callback will try to find a generated method for the
158156 // target recipient type, and just invoke it to get the delegate to cache and use later.
159157 // 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." ) ]
160159 static Action < IMessenger , object , TToken > LoadRegistrationMethodsForType ( Type recipientType )
161160 {
162161 if ( recipientType . Assembly . GetType ( "CommunityToolkit.Mvvm.Messaging.__Internals.__IMessengerExtensions" ) is Type extensionsType &&
@@ -224,7 +223,6 @@ from registrationMethod in registrationMethods
224223
225224 return Expression . Lambda < Action < IMessenger , object , TToken > > ( body , arg0 , arg1 , arg2 ) . Compile ( ) ;
226225 }
227- #pragma warning restore IL2026
228226
229227 // Get or compute the registration method for the current recipient type.
230228 // As in CommunityToolkit.Diagnostics.TypeExtensions.ToTypeString, we use a lambda
@@ -233,7 +231,7 @@ from registrationMethod in registrationMethods
233231 // For more info on this, see the related issue at https://github.com/dotnet/roslyn/issues/5835.
234232 Action < IMessenger , object , TToken > registrationAction = DiscoveredRecipients < TToken > . RegistrationMethods . GetValue (
235233 recipient . GetType ( ) ,
236- static t => LoadRegistrationMethodsForType ( t ) ) ;
234+ [ RequiresUnreferencedCode ( "The type of the current instance cannot be statically discovered." ) ] static ( t ) => LoadRegistrationMethodsForType ( t ) ) ;
237235
238236 // Invoke the cached delegate to actually execute the message registration
239237 registrationAction ( messenger , recipient , token ) ;
0 commit comments