Chris Laplante
Chris Laplante

Reputation: 29668

Question about external libraries and namespaces

In a class library I am building, I am including files from HtmlAgilityPack. My question: Should I wrap my namespace around the HtmlAgilityPack classes? For example:

namespace HtmlAgilityPack {
    internal... // blah blah blah

}

becomes:

namespace MyNamespace {
    namespace HtmlAgilityPack {
        internal... // blah blah blah

    }
}

I am thinking of doing this to prevent conflicts in projects that already use HtmlAgilityPack. Is there any other reason to do this? Thanks,

Upvotes: 2

Views: 393

Answers (3)

Saeed Amiri
Saeed Amiri

Reputation: 22565

Instead of doing:

namespace MyNamespace {
    namespace HtmlAgilityPack {
        internal... // blah blah blah

    }
}

do

namespace MyNamespace.HtmlAgilityPack 
{
        internal... // blah blah blah
}

this is a common way, yes doing this is good, and because of this namespaces are alive.

Upvotes: 1

BrokenGlass
BrokenGlass

Reputation: 161012

Users should be able to uniquely identify class names using namespaces, that's the whole idea of namespaces in the first place imo. There are workarounds like aliases but I wouldn't introduce this problem for the users of your library. That being the case I would wrap the HtmlAgility namespace as you suggested.

Upvotes: 1

J.W.
J.W.

Reputation: 18181

No, I don't think you need worry about this. For projects which already use HtmlAgilityPack, you can just simply share the HtmlAgilityPack namespace with them. I don't see the conflict issue here.

Upvotes: 1

Related Questions