You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Mapster Tool] Add support for global:: to disambiguate type names in generated mappers #1020
In this case the compiler will trigger a CS0234 The type or namespace 'Models' does not exist in the namespace 'Prefix.Company' (are you missing an assembly reference?)
due to the standard namespace resolution strategy of the compiler.
Even qualifying the name like this
does not fix the error, and the only proper fix is to use the global:: qualifier
namespacePrefix.Company.Mappers{usingThirdParty.Models;// The following is equivalent to inline global qualificatio// using global::Company.Models;publicpartialclassMapper{global::Company.Models.MyModelMap(OtherModelmodel);}}
The Mapster tool allows to generate mappers with a fully qualified name, but it does not prefix types with global:: (neither provides an option to do so).
It would be nice if such feature was added.
I am willing to provide a PR eventually.
Hi @BladeWise.
With which Mapster Tool settings does the generation of using statements occur after the namespace declaration?
This looks more like some kind of output sequence bug 🤔
The standard behavior is as follows:
// generated file
using ThirdParty.Models;
using Company.Models;
namespace Prefix.Company.Mappers
{
public partial class Mapper
{
MyModel Map(OtherModel model);
}
}
// end generated file
My example was probably misleading due to my linter moving usings inside the namespace (which changes the namespace resolution rules), but the problem is with the -p option which generates namespace-qualified type names.
The type or namespace name 'Models' does not exist in the namespace 'Prefix.Company' (are you missing an assembly reference?)
The simpler fix would be to include a global:: prefix to the namespace-qualified type names (which is quite common in generators to avoid namespace resolution issues)
@andrerav@stagep
I think this can be done as a default behavior when generation using the -p option.
If this doesn’t cause problems when using aliases. (need tests)
Activity
DocSvartz commentedon Sep 16, 2026
Hi @BladeWise.
With which Mapster Tool settings does the generation of
usingstatements occur after the namespace declaration?This looks more like some kind of output sequence bug 🤔
The standard behavior is as follows:
BladeWise commentedon Sep 17, 2026
My example was probably misleading due to my linter moving usings inside the namespace (which changes the namespace resolution rules), but the problem is with the -p option which generates namespace-qualified type names.
Attached is a solution with a repro project.
What happens is that without -p Mapster generates this (as you said)
which compiles fine, but using -p it generats this
which exhibits the problem
The simpler fix would be to include a
global::prefix to the namespace-qualified type names (which is quite common in generators to avoid namespace resolution issues)eventually, enabling this behavior with a dedicated switch.
Sorry for the misleading sample in my first post!
DocSvartz commentedon Sep 17, 2026
@andrerav @stagep
I think this can be done as a default behavior when generation using the
-poption.If this doesn’t cause problems when using aliases. (need tests)
What are your think about this?
DocSvartz commentedon Oct 21, 2026
Hi, @BladeWise In the pre-release version 10.0.14-pre01,
the
-poption generates types using theglobal::prefix.BladeWise commentedon Oct 21, 2026
Thanks a lot for the fix!