Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[Mapster Tool] Add support for global:: to disambiguate type names in generated mappers

オープン
#1,020 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

@DocSvartz がすでに取り組んでいます。

2026年10月19日 から。

  • #1026 @DocSvartz による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
65/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp
領域
tooling

調査の方向性

Mapster ツールに既にある完全修飾名の生成サポートから始め、生成された型名がどのように出力されるかを追跡します。global:: 修飾子用のオプションを追加し、モデルの namespace が mapper の namespace と衝突する場合に、生成された mapper がコンパイルできることを検証します。

索引モデルが issue の本文から書いたものです。

説明

improvement

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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MapsterMapper/Mapster のほかの issue

MapsterMapper/Mapster の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。