@@ -153,6 +153,20 @@ static Action<IMessenger, object, TToken> LoadRegistrationMethodsForType(Type re
153
153
// The LINQ codegen bloat is not really important for the same reason.
154
154
static Action < IMessenger , object , TToken > LoadRegistrationMethodsForTypeFallback ( Type recipientType )
155
155
{
156
+ // Get the collection of validation methods
157
+ MethodInfo [ ] registrationMethods = (
158
+ from interfaceType in recipientType . GetInterfaces ( )
159
+ where interfaceType . IsGenericType &&
160
+ interfaceType . GetGenericTypeDefinition ( ) == typeof ( IRecipient < > )
161
+ let messageType = interfaceType . GenericTypeArguments [ 0 ]
162
+ select MethodInfos . RegisterIRecipient . MakeGenericMethod ( messageType , typeof ( TToken ) ) ) . ToArray ( ) ;
163
+
164
+ // Short path if there are no message handlers to register
165
+ if ( registrationMethods . Length == 0 )
166
+ {
167
+ return static ( _ , _ , _ ) => { } ;
168
+ }
169
+
156
170
// Input parameters (IMessenger instance, non-generic recipient, token)
157
171
ParameterExpression
158
172
arg0 = Expression . Parameter ( typeof ( IMessenger ) ) ,
@@ -178,11 +192,7 @@ static Action<IMessenger, object, TToken> LoadRegistrationMethodsForTypeFallback
178
192
// We also add an explicit object conversion to cast the input recipient type to
179
193
// the actual specific type, so that the exposed message handlers are accessible.
180
194
BlockExpression body = Expression . Block (
181
- from interfaceType in recipientType . GetInterfaces ( )
182
- where interfaceType . IsGenericType &&
183
- interfaceType . GetGenericTypeDefinition ( ) == typeof ( IRecipient < > )
184
- let messageType = interfaceType . GenericTypeArguments [ 0 ]
185
- let registrationMethod = MethodInfos . RegisterIRecipient . MakeGenericMethod ( messageType , typeof ( TToken ) )
195
+ from registrationMethod in registrationMethods
186
196
select Expression . Call ( registrationMethod , new Expression [ ]
187
197
{
188
198
arg0 ,
0 commit comments