/CopyObject

A small library for copying plain objects with identically-named properties

Primary LanguageC#MIT LicenseMIT

Build status Nuget

The idea here is to copy one object to another or to a new instance, typically from some kind of DTO to a database model class or vice versa via extension method. For example

using CopyObjectLibrary;

...

var dest = source.CopyAs<SomeType>();

This would copy matching properties of source to a new instance of type SomeType dest.

This mapper requires properties to be identically-named and a type that's close enough. "Close enough" means T == T but also T == Nullable<T> or Nullable<T> == T.

See examples in tests.

Reference

CopyObjectLibrary.ObjectExtensions ObjectExtensions.cs

Methods

  • T CopyAs (this object object)
  • T CopyAs (this object object, T instance)
  • void CopyTo (this object object, T instance)
  • bool Equals (PropertyInfo x, PropertyInfo y)
  • int GetHashCode (PropertyInfo obj)

CopyObjectLibrary.TypeExtensions TypeExtensions.cs

Methods