Monday, May 02, 2005

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:

if (!String.IsNullOrEmpty(urlString)) {

    System.Reflection.Assembly assembly = BuildManager.GetCompiledAssembly(urlString);

    theTypeIWant = assembly.GetType(typeString, true);

}

else {

    theTypeIWant = Type.GetType(typeString, true);

}

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.

posted on Monday, May 02, 2005 10:16:09 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]
Related posts:
9-year Anniversary (yesterday)
LinqToStdf now on CodePlex
Image Slicer for Deep Zoom in Silverlight 2
Silverlight limitations and Constrained Callvirt in IL
Happy Birthday Peter
What are the generic Delegates in the framework for?
Tracked by:
"car logos" (car logos) [Trackback]
"volo ivrea" (volo ivrea) [Trackback]
"Western Michigan West Michigan Grand Rapids" (Western Michigan West Michigan Gr... [Trackback]
"synthetic oil" (synthetic oil) [Trackback]
"mexican flag" (mexican flag) [Trackback]
"eta phi beta" (eta phi beta) [Trackback]
"azioni quotazioni" (azioni quotazioni) [Trackback]
"Airsoft Spring Guns" (Airsoft Spring Guns) [Trackback]
"soccer videos" (soccer videos) [Trackback]
"fucking farm girls" (fucking farm girls) [Trackback]
"Free Antivirus Downloads" (Free Antivirus Downloads) [Trackback]
"wild blow jobs" (wild blow jobs) [Trackback]
"the poem poor girl" (the poem poor girl) [Trackback]
"filthy white bitch" (filthy white bitch) [Trackback]
"Orlando%2C FL" (Orlando%2C FL) [Trackback]
"renovation hardware" (renovation hardware) [Trackback]
"shooting bench" (shooting bench) [Trackback]
"hunting south dakota" (hunting south dakota) [Trackback]
"Last Minute Flights" (Last Minute Flights) [Trackback]
"hsbc internet banking" (hsbc internet banking) [Trackback]
"alarm systems arlington" (alarm systems arlington) [Trackback]
"online psychic chat" (online psychic chat) [Trackback]
"SIP IP Handset" (SIP IP Handset) [Trackback]
"grand cherokee" (grand cherokee) [Trackback]
"snuff hogtied chloroformed video" (snuff hogtied chloroformed video) [Trackback]
"DYNAMARK 12 HP 39" (DYNAMARK 12 HP 39) [Trackback]
"U.S. Bishops Conference for 2005 in Brussels" (U.S. Bishops Conference for 2005... [Trackback]
"open a restaurant" (open a restaurant) [Trackback]
"vero beach%2C fl" (vero beach%2C fl) [Trackback]
"penn state %2B sweatshirt" (penn state %2B sweatshirt) [Trackback]
"jacobs institute of womens health" (jacobs institute of womens health) [Trackback]
"erotic massage in chicago" (erotic massage in chicago) [Trackback]
"mom car fuck" (mom car fuck) [Trackback]