LoginSignup
2
5

More than 5 years have passed since last update.

オブジェクトの詰め替え、コピーに便利なAutoMapper、DeepCloner

Posted at

はじめに

だいたい似たようなメンバだけど、微妙に違うオブジェクトに中身を詰め替えたい!
という場合に便利なライブラリAutoMapperとオブジェクトをディープクローンしたい!という場合に使うDeepClonerのメモです。
世の中に解説記事が出回っているのでリンクだけ。

AutoMapper

公式サイト/Github

https://automapper.org/
https://github.com/AutoMapper/AutoMapper

nugetパッケージ

nugetパッケージマネージャーコンソール
Install-Package AutoMapper

先人の知恵

https://blog.shibayan.jp/entry/20130203/1359898568
http://iyemon018.hatenablog.com/entry/2015/09/26/185822

ASP.NET MVC + Unity(DIコンテナ)で使う

DeepCloner

全く同じオブジェクトをもう1個作りたい場合はDeepClonerを使う

Github

nugetパッケージ

nugetパッケージマネージャーコンソール
Install-Package DeepCloner

使い方

オブジェクトに拡張メソッドが追加されるので下記のようにディープクローンできます。
他の細かい使い方はGithubのREADMEを参照。

C#
using Force.DeepCloner

Hoge hoge2 = hoge1.DeepClone();
2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5