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

Mapping an object with getter only properties seems to be broken in v10.0.6 (works as expected in 7.4.0)

オープン
#900 コメント 9 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
50/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
csharp
領域
backend

調査の方向性

まず、提供された C# の再現コードを Mapster v10.0.6 で実行し、カスタム Dto-to-Entity マッピングを v7.4.0 と比較します。Data が getter-only の Value を持つ場合に、既存の Entity へのマッピングがどのように動作するかを追跡し、既存の Entity が新しい Data の値を受け取り、他の示されたケースも引き続きパスすることを確認できた時点で完了とします。

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

説明

configuration problem

Hello. I am trying to map an object with getter-only properties using a custom Map functon. This seems to be broken in v10.0.6, while it was fine in v7.4.0. See the following sample:

var typeAdapterConfig = new Mapster.TypeAdapterConfig();
typeAdapterConfig.Scan(typeof(Program).Assembly);
typeAdapterConfig.Compile();
var mapper = new MapsterMapper.Mapper(typeAdapterConfig);

var dto = new Dto { Data = new("new") };
Console.WriteLine(mapper.Map(dto, new Entity { Data = new("old") }).Data?.Value); // outputs "old" with v10.0.6, outputs "new" with v7.4.0
Console.WriteLine(mapper.Map(dto, new Entity()).Data?.Value); // outputs "new" with both v10.0.6 and v7.4.0
Console.WriteLine(mapper.Map<Entity>(dto).Data?.Value); // outputs "new" with both v10.0.6 and v7.4.0

class Dto { public Data? Data { get; set; } }
class Entity { public Data? Data { get; set; } }
class Data(string value) { public string Value => value; }

class Mappings : Mapster.IRegister
{
    public void Register(Mapster.TypeAdapterConfig config)
    {
        config.NewConfig<Dto, Entity>()
            .Map(x => x.Data, x => x.Data == null ? null : new Data(x.Data.Value));
    }
}

Specifically this case seems to be broken:

var dto = new Dto { Data = new("new") };
var entity = mapper.Map(dto, new Entity { Data = new("old") });

I would expect the result entity's Data property to be mapped correctly from the source dto, as specified in the mapping function:
config.NewConfig<Dto, Entity>().Map(x => x.Data, x => x.Data == null ? null : new Data(x.Data.Value));
As noted, Mapster v7.4.0 seems to be find, but v10.0.* seems to be broken.
Or maybe I am missing something here, please advise, thank you.

主要言語
C#
スター
5.2k
フォーク
411
平均マージ
1日 8時間
マージ済み PR(30日)
4

環境構築

はじめの一歩

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

MapsterMapper/Mapster のほかの issue

MapsterMapper/Mapster の issue をすべて見る

似ている issue

C# の issue をもっと見る

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

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