Class with same name as namespace
In the same app still (Ilanos), in my
Ilanos.Application
proj I have a lot of classes that are supposed to use the Joke
class.
However, for the sake of organization, I'm separating them like this:
The problem of that is the namespace name. The JokeResponseMapper
, for example, would be at the namespace Ilanos.Application.Mappers.Joke
while the Joke
entity/model class is at Ilanos.Core.Entities
.
The compiler complains that the Ilanos.Application.Mappers.Joke
namespace and the Joke
class "have the same name", even if they're different, is there a way to keep the organization and have the named classes as they are?14 Replies
you'll have to fully qualify the class name (Ilanos.Core.Entities.Joke) to avoid that conflict, i recommend changing your naming instead
Do you really have multiple mapper classes for a single entity?
Alternatively, you can use a type alias
yes, for my create command and response
also that happened in my service stuff too
too late for name changes, so full path it is, ig
Or a type alias
using JokeModel = Ilanos.Core.Entities.Joke;
And use JokeModel
why isn't there the difference for the compiler, though?
that seems a bit counterintuitive
what do you mean
I mean why does the compiler doesn't differenciate namespaces and classes? They're different things
because it becomes ambiguous what you're refering to
yes, but why is it ambiguous, doesn't the compiler have different "memories" for those?
that's how I thought it was implemented at least
it depends exactly on what the code is that's generating the error
I was just using the Joke class while a namespace ending in Joke was in scop
hey, you can also write
global::Namespaces.Joke
, imagine thatwdym?
when you have name clashing you can add global:: to identify stuff
and global::Joke is funny