I have previously written a blog titled "cross-assembly reflection". The method used for cross-assembly loading is to first load the assembly of the target type, use Assembly again. the GetType method obtains the type. Later, Luna's comment said that type can be used directly. getType ("<fully qualified Class Name>, <Assembly>") to load the type. I checked msdn and mentioned this in msdn, I remember this solution. However, when this method is used for type loading across assemblies, null is always returned. Is msdn incorrect? I don't know. (Hope you can tell me what you know ).
In spring.net, configuration files usually contain configuration items similar to the following: <object name = "datastreamhelper" type = "datacenterbase. Common. datastreamhelper, datacenterbase"/>
The value of "type" in the configuration is exactly the same as the parameter format of the type. GetType method. So I guess spring.net uses the type. GetType method. I checked the source code of spring.net. Unexpectedly, spring.net did not use the type. GetType shortcut, but still used the Assembly. GetType method. I don't know why.
For future convenience, I encapsulated a static method to support any type of loading. 1 # region GetType
2 // assemblyname does not require an extension. If the target type is in the current Assembly, assemblyname is null.
3 Public static type GetType (string typefullname, string assemblyname)
4 {
5 If (assemblyname = NULL)
6 {
7 return type. GetType (typefullname );
8}
9
10 // search for the Assembly loaded in the current domain
11 Assembly [] asses = appdomain. currentdomain. getassemblies ();
12 foreach (Assembly ass in asses)
13 {
14 string [] names = ass. fullname. Split (',');
15 if (Names [0]. Trim () = assemblyname. Trim ())
16 {
17 return ass. GetType (typefullname );
18}
19}
20
21 // load the Target Assembly
22 Assembly tarassem = assembly. loadwithpartialname (assemblyname );
23 if (tarassem! = NULL)
24 {
25 return tarassem. GetType (typefullname );
26}
27
28 return NULL;
29}
30 # endregion
Who has successful experience in loading non-current Assembly types using type. GetType? Thanks for sharing.