Is there any way to read the asp.net Import directives at runtime? I have an ExpressionBuilder that is passed a number of class names. Right now I have to fully qulify these names but if I could read the namespaces from within the ExpressionBuilder, I can save myself a lot of typeing…
<%@ Import namespace="MyNameSpace.Data.Library" %>
//
//
string GetNamespace()
{
return Page.blablabla(); // MyNameSpace.Data.Library
}
a bit more info:
I am using System.Web.BuildManager.GetType() to get the type of my object. When does (or can it) somehow reference the Import directives?
After researching the subject, I don’t think this can be done. You have to fully qualify your controls if the page does not import the namespace explcitly or implicitly (via the web.config).
In addition, I believe namespaces are not a “property” of a class. I believe the compiler will just use them at compile time for checking and then will actually fully qualify the controls/classes when it compiles. In other words, compiled code does not have a distinct list of “using or import” statements to evaluate.