[Mapster Tool] Add support for global:: to disambiguate type names in generated mappers
評価
調査の方向性
Mapster ツールに既にある完全修飾名の生成サポートから始め、生成された型名がどのように出力されるかを追跡します。global:: 修飾子用のオプションを追加し、モデルの namespace が mapper の namespace と衝突する場合に、生成された mapper がコンパイルできることを検証します。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C#
- スター
- 5.2k
- フォーク
- 409
- 平均マージ
- 3日 4時間
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
MapsterMapper/Mapster のほかの issue
-
.NET Matrixオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
MapsterMapper/Mapster#1003 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
MapsterMapper/Mapster#1024 · コメント 1 件 ·
-
Mapster.Tool - PropertySettingBuilder.Map(member, mapFunc, targetPropertyName) method is not working as expected!対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
MapsterMapper/Mapster#1017 · コメント 6 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 57/100
MapsterMapper/Mapster#1007 · コメント 5 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
MapsterMapper/Mapster#1005 ·
MapsterMapper/Mapster の issue をすべて見る
似ている issue
-
bug priority: P2
難易度 1/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信
-
[Docs] README/PRIVACY still name AppCenter although v1.5.6.0+ uses the Microsoft Store Services SDKオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Azure/azure-sdk-tools#17317 ·
メンテナーはふだん 1 日以内に返信
-
Test
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
メンテナーはふだん 1 日以内に返信