T
Thomas Sondergaard
I'd like to hear sugestions for how you would go about implementing this
function
public class ReflectionUtil {
public static bool isNameSpace(string name) {
// return true if 'name' is a namespace in any of
// the loaded assemblies
}
}
I understand that namespaces are not something .net understands, it is
simply something C# (and many other .net languages) defines and as far as
the .net runtime is concerned they just end up being part of the fully
qualified names of the types that are defined in assemblies. Well, all the
same there must be a way, possibly computationally expensive, to check
whether a given string 'name' indicates a namespace.
Test cases (may not compile)
public void testIsNameSpace() {
// Assuming at least mscorlib.dll is loaded so the System.* stuff is
available
Assert(ReflectionUtil.isNameSpace("System"));
Assert(ReflectionUtil.isNameSpace("System.Collections"));
Assert(ReflectionUtil.isNameSpace("System.Runtime.InteropServices"));
Assert(!ReflectionUtil.isNameSpace("NoSuchNameSpace"));
Assert(!ReflectionUtil.isNameSpace("System.NotThereEither"));
}
Any ideas. Code is welcome
Cheers,
Thomas
function
public class ReflectionUtil {
public static bool isNameSpace(string name) {
// return true if 'name' is a namespace in any of
// the loaded assemblies
}
}
I understand that namespaces are not something .net understands, it is
simply something C# (and many other .net languages) defines and as far as
the .net runtime is concerned they just end up being part of the fully
qualified names of the types that are defined in assemblies. Well, all the
same there must be a way, possibly computationally expensive, to check
whether a given string 'name' indicates a namespace.
Test cases (may not compile)
public void testIsNameSpace() {
// Assuming at least mscorlib.dll is loaded so the System.* stuff is
available
Assert(ReflectionUtil.isNameSpace("System"));
Assert(ReflectionUtil.isNameSpace("System.Collections"));
Assert(ReflectionUtil.isNameSpace("System.Runtime.InteropServices"));
Assert(!ReflectionUtil.isNameSpace("NoSuchNameSpace"));
Assert(!ReflectionUtil.isNameSpace("System.NotThereEither"));
}
Any ideas. Code is welcome
Cheers,
Thomas