user3241130
user3241130

Reputation: 85

C# Set default namespace when conflicted

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.

Upvotes: 1

Views: 393

Answers (2)

faby
faby

Reputation: 7556

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

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500913

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.

Upvotes: 1

Related Questions