asp.net mvc 4 - Understanding what a foreach loop is looking for in the AppDomain -


i digging though mvc example downloaded few months ago , ran across foreach loop uses appdomain.currentdomain. hoping explain foreach loop searching for.

foreach (var assembly in appdomain.currentdomain               .getassemblies()               .where(a => a.getname().name.contains("spring")))         {             var configtypes = assembly               .gettypes()               .where(t => t.basetype != null                 && t.isclass                 && !t.isabstract                 && t.basetype.isgenerictype                 && t.basetype.getgenerictypedefinition() == typeof(entitytypeconfiguration<>)                 && t.basetype.getgenericarguments().any(ta => _modelinterfacetype.isassignablefrom(ta)));              foreach (var type in configtypes)             {                 var entitytype = type.basetype.getgenericarguments().single();                  var entityconfig = assembly.createinstance(type.fullname);                  addmethod.makegenericmethod(entitytype)                   .invoke(modelbuilder.configurations, new object[] { entityconfig });             }         } 

i understand runs loop 1 time per assembly finds in appdomain.currentdomain.getassemblies , .where() filter not sure how filter working or data searching in appdomain.

note: have never used appdomain function , don't understand how works.

it may worth reading bit appdomains.
let's assume understand appdomain , how relevant asp.net.
see this link explanation of appdomain.getassemblies method.

the query searching assemblies loaded current appdomain find name of assembly contains "spring".

spring: application framework.

i assume there functionality in sample dependent on whether or not spring referenced. tell more need see rest of code.

after edit @matthew verstraete#

ok, little bit more code explain.
so, each spring assembly (or @ least assembly has "spring" in name...) using reflection @ types.
want things are:
- subtypes of (t.basetype != null)
- aren't value types (t.isclass)
- concrete (no abstract, no interfaces - !t.isabstract), have type parameters (t.basetype.isgenerictype)
- gets interesting: looking subclasses of entitytypeconfiguration<>
- member of our can assigned generic type ta => _modelinterfacetype.isassignablefrom(ta))

once code has found suitable types continues on create instance of each invoke generic method (see also) on modelbuilder each created instance.

what digging through code first configuration of entity framework.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -