We have a big configuration file that maps business logic concepts to their currently used implementations so we can dynamically switch these out. Under ASP.NET 1.0, all those implementations were in assemblies with "well-known" names (meaning we know them deterministically before compile-time). Some of the implementations were in nested classes of user controls (we'll save the debate over whether that is a good idea for another time). This means that the ASP.NET compiler is now in charge of them, which makes their names more difficult to discover.
Luckily, there's someone looking out for us here. The System.Web.Compilation namespace has all kinds of goodies to help us out here, namely the BuildManager class. It has a GetType overload that at first glance appears to do exactly what we want, unfortunately it only seems to work if the assembly in question has already been loaded. This is not usually the case when our configuration code runs the first time. Instead, you can use a combination of GetCompiledAssembly and good ol' Assembly.GetType. So now, instead of knowing the assembly name, we need to know the virtual path to the compiled control. So here's a snippet that does generally what I want:
System.Reflection.
theTypeIWant = assembly.GetType(typeString,
}
theTypeIWant =
So, for those types that reside under ASP.NET's control, I add the virtual path to the configuration and leave out the assembly name, and use it's presence to determine if the BuildManager needs to get involved.
Also notice the wonderful String.IsNullOrEmpty method. Now, if there were only some kind of operator I could use to be even lazier about that check.
Remember Me
Page rendered at Monday, January 05, 2009 5:46:14 PM (Pacific Standard Time, UTC-08:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.