Fabrice's weblog

Tools and Source

News

My .NET Toolbox
An error occured. See the script errors signaled by your web browser.
No tools selected yet
.NET tools by SharpToolbox.com

Read sample chapters or buy LINQ in Action now!
Our LINQ book is also available on AMAZON

.NET jobs

Emplois .NET

Tuneo

ASP.NET Hosting transatlantys

Contact

Me

Others

Selected content

What about some refactoring?

When you work with configuration files throughout the framework and the application blocks, you encounter assembly qualified names. Assembly qualified names (AQN) look like this: "MyNamespace.MyClass, MyAssembly". This is useful, because a string like this gives you everything you need to find a type. You can simply use Type.GetType() to access a type, based on its AQN.

I was searching for a method to parse AQNs for my own configuration files because I need to call Activator.CreateInstance(string, string), which expects assembly name and type name broken apart.
Well, I looked in the framework, and I found several methods.
There is Assembly.ParseTypeName(). There is TypeInfo.ParseTypeAndAssembly(). There is RemotingXmlConfigFileParser.ParseType().
The first one is internal to the CLR, the others have implementations of their own. Maybe more implementation are scattered around the framework, and maybe more in application blocks or other apps.

I'd say it's time for some refactoring to create one and only method in the framework. It's not because writing this method is difficult, but it's violating the DRY principle. What if AQNs change in .NET 3.2?
It would be nice if this method gets public too so we don't have to write our own...

Comments

TrackBack said:

Take Outs for 12 March 2004
# March 16, 2004 10:07 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)