1

Is it possible to set a default namespace for the compiler to look at when you have a conflict between two namespaces?

My problem comes from using iTextSharp in a C# ASP.NET application. I'm adding the iTextSharp library to a page but this library conflicts a few items with the standard System WebControls library.

I know I can fully qualify each class reference to resolve the conflict and I know I can alias the namespaces to save myself using the full qualifications everywhere.

I'm wondering if it is possible to alias one namespace (iTextSharp) and default all references in my code to the unaliased namespace (WebControls)?

So for example if I aliased iTextSharp as "text":

ListItem l = new ListItem();

would reference Webcontrols but

text.ListItem l = new text.ListItem();

would reference iTextSharp.

I ask as there are a whole bunch of webcontrols on the page, and I don't particularly want to go through all the code and qualify each and every one of them.

Thanks in advance for any responses.

2 Answers 2

1

Well not quite like that, but you could use a namespace alias directive:

using System.Web.UI.WebControls;
using text = iTextSharp;
...

text::ListItem l = new text::ListItem();

You'd then not want a straight using directive for iTextSharp, as that would make just ListItem ambiguous again.

Sign up to request clarification or add additional context in comments.

5 Comments

I didn't see you answer. Forgive me, i see that looks very similar to yours
@faby: Except it's the other way round from what the question requests ;)
Just for clarification, If I set my 'Using' directives as you have above: 'ListItem l = new ListItem();' will reference WebControls but 'text::ListItem l = new text::ListItem();' will reference iTextSharp?
@user3241130: Yes, exactly.
Tested it there, works perfectly, thanks a million!!
0

for this porpuse you can use aliases

using WebControls = System.Web.UI.WebControls;

so when you refer WebControls you are using System.Web.UI.WebControls

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.