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.
CopyObjectLibrary.ObjectExtensions ObjectExtensions.cs
- 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
- bool IsSimpleType (this Type type)
- bool IsNullableGeneric (this Type type)
- bool IsTypeCloseEnough (this Type type, Type compareWith)