| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ObjectGraphExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Runtime.CompilerServices; |
| | | 9 | | |
| | | 10 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 11 | | namespace MyNet.Reflection; |
| | | 12 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 13 | | |
| | | 14 | | public static class ObjectGraphExtensions |
| | | 15 | | { |
| | | 16 | | extension<T>(T obj) |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Returns a Deep Clone / Deep Copy of an object of type T using a recursive call to the CloneMethod specified |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="options">Options for deep copy.</param> |
| | | 22 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 9 | 23 | | public T? DeepClone(DeepCloneOptions? options = null) => ObjectGraphMapper.Clone(obj, options); |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Populates the fields and properties of the current object with the values from the specified source object o |
| | | 27 | | /// </summary> |
| | | 28 | | /// <param name="source">The source object from which to copy values.</param> |
| | | 29 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 30 | | public void PopulateFrom(T source) |
| | | 31 | | { |
| | 12 | 32 | | ArgumentNullException.ThrowIfNull(obj); |
| | 12 | 33 | | ArgumentNullException.ThrowIfNull(source); |
| | | 34 | | |
| | 12 | 35 | | ObjectGraphMapper.Populate(source, obj); |
| | 12 | 36 | | } |
| | | 37 | | } |
| | | 38 | | } |
| | | 39 | | |