@@ -185,12 +185,12 @@ public bool SortTypeTryGetValue(Symbol sort, out Type/*?*/ t)
185
185
/// Get the default type of the sort
186
186
/// </summary>
187
187
public Type DefaultSortType ( Symbol sort )
188
- {
188
+ {
189
189
Type result ;
190
190
if ( sortType . TryGetValue ( sort , out result ) )
191
191
return result ;
192
192
193
- string [ ] namespaces = new string [ ] { "NModel" , "NModel.Internals" , "NModel.Terms" , "System" } ;
193
+ string [ ] namespaces = new string [ ] { "NModel" , "NModel.Internals" , "NModel.Terms" , "System" } ;
194
194
195
195
if ( sort . DomainParameters != null && sort . DomainParameters . Count > 0 )
196
196
{
@@ -241,15 +241,59 @@ public Type DefaultSortType(Symbol sort)
241
241
break ;
242
242
}
243
243
}
244
+ if ( result == null )
245
+ // If the execution got here it means that it didn't find the type of sort
246
+ // in this model and in the NModel framework.
247
+ // Check for the type in the AppDomain assemblies -
248
+ // Is it a type of another model program that is being composed with this one
249
+ result = getSortTypeFromAppDomainAssemblies ( namespaces , sort . Name ) ;
244
250
245
251
if ( result == null )
246
- throw new ArgumentException ( "No default type for sort " + sort . ToString ( ) ) ;
252
+ throw new ArgumentException ( "No default type for sort " + sort . ToString ( ) ) ;
247
253
248
254
this . RegisterSortType ( sort , result ) ;
249
255
return result ;
250
256
}
251
257
258
+ /// <summary>
259
+ /// Check for the type in the AppDomain assemblies -
260
+ /// Is it a type of another model program that is being composed with this one
261
+ /// Exclude from checking all the namespaces that have been checked already
262
+ /// </summary>
263
+ /// <param name="excludeNameSpaces"></param>
264
+ /// <param name="sortTypeName"></param>
265
+ /// <returns>Type - the type of the given sort, or null if a matching type was not found</returns>
266
+ private Type getSortTypeFromAppDomainAssemblies ( string [ ] excludeNameSpaces , string sortTypeName )
267
+ {
268
+ Type thisSortType = null ;
252
269
270
+ // Get all the assemblies loaded into this AppDomain.
271
+ foreach ( Assembly thisAssembly in AppDomain . CurrentDomain . GetAssemblies ( ) )
272
+ {
273
+ int i ;
274
+ // Exclude all the namespaces that have been checked already
275
+ for ( i = 0 ; i < excludeNameSpaces . Length ; ++ i )
276
+ {
277
+ if ( thisAssembly . GetName ( ) . Name == excludeNameSpaces [ i ] )
278
+ break ;
279
+ }
280
+ if ( i == excludeNameSpaces . Length )
281
+ {
282
+ foreach ( Type t in thisAssembly . GetExportedTypes ( ) )
283
+ {
284
+ if ( t . Name == sortTypeName )
285
+ {
286
+ // Found it!
287
+ thisSortType = t ;
288
+ break ;
289
+ }
290
+ }
291
+ }
292
+ if ( thisSortType != null )
293
+ break ;
294
+ }
295
+ return thisSortType ;
296
+ }
253
297
254
298
///// <summary>
255
299
///// Accesses the mapping of .NET types to sorts (abstract types used to connect model programs). This
0 commit comments