In some cases it could be useful to generate sources where type names are fully qualified with global:: prefix.
If the mapper class is generated in a namespace that partially collides with the one where models are defined, compilation fails.
An example:
namespace Company.Models
{
public class MyModel
{
}
}
namespace ThirdParty.Models
{
public class OtherModel
{
}
}
namespace Prefix.Company.Mappers
{
using ThirdParty.Models;
using Company.Models;
public partial class Mapper
{
MyModel Map(OtherModel model);
}
}
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
namespace Prefix.Company.Mappers
{
using ThirdParty.Models;
public partial class Mapper
{
Company.Models.MyModel Map(OtherModel model);
}
}
does not fix the error, and the only proper fix is to use the global:: qualifier
namespace Prefix.Company.Mappers
{
using ThirdParty.Models;
// The following is equivalent to inline global qualificatio
// using global::Company.Models;
public partial class Mapper
{
global::Company.Models.MyModel Map(OtherModel model);
}
}
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.
In some cases it could be useful to generate sources where type names are fully qualified with
global::prefix.If the mapper class is generated in a namespace that partially collides with the one where models are defined, compilation fails.
An example:
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::qualifierThe 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.