Skip to content

Commit b6f5528

Browse files
committed
DataObject to DTO
1 parent 8f5e8f6 commit b6f5528

5 files changed

Lines changed: 40 additions & 37 deletions

File tree

PG.Commons/PG.Commons/Data/DataObjectMapperBase.cs renamed to PG.Commons/PG.Commons/Data/DataTransferObjectMapperBase.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
namespace PG.Commons.Data;
44

55
/// <summary>
6-
/// Container class allowing to map from a data objct to a peer and vice versa
6+
/// Container class allowing to map from a data objct to a peer and vice versa.
7+
/// <br />
8+
/// @lgr: check if fully replaceable with AutoMapper
79
/// </summary>
8-
/// <typeparam name="TDataObject"></typeparam>
10+
/// <typeparam name="TDto"></typeparam>
911
/// <typeparam name="TPeer"></typeparam>
10-
public abstract class DataObjectMapperBase<TDataObject, TPeer>
12+
public abstract class DataTransferObjectMapperBase<TDto, TPeer>
1113
{
12-
private readonly DataObjectMappings<TDataObject, TPeer> _mappings;
14+
private readonly DataTransferObjectMappings<TDto, TPeer> _mappings;
1315

1416
/// <summary>
1517
/// .ctor
1618
/// </summary>
17-
protected DataObjectMapperBase()
19+
protected DataTransferObjectMapperBase()
1820
{
19-
var mappings = new DataObjectMappings<TDataObject, TPeer>();
21+
var mappings = new DataTransferObjectMappings<TDto, TPeer>();
2022
// ReSharper disable once VirtualMemberCallInConstructor
2123
InitMappings(mappings);
2224
_mappings = mappings;
@@ -26,7 +28,7 @@ protected DataObjectMapperBase()
2628
/// Method is overridden by subclasses to initialize the mappings.
2729
/// </summary>
2830
/// <param name="mappings"></param>
29-
protected abstract void InitMappings(DataObjectMappings<TDataObject, TPeer> mappings);
31+
protected abstract void InitMappings(DataTransferObjectMappings<TDto, TPeer> mappings);
3032

3133

3234
/// <summary>
@@ -36,9 +38,9 @@ protected DataObjectMapperBase()
3638
/// <param name="dataObject"></param>
3739
/// <returns></returns>
3840
/// <exception cref="ArgumentNullException"></exception>
39-
protected bool ToDataObject(TPeer source, TDataObject dataObject)
41+
protected bool ToDto(TPeer source, TDto dataObject)
4042
{
41-
return _mappings.ToDataObject(source ?? throw new ArgumentNullException(nameof(source)), dataObject);
43+
return _mappings.ToDto(source ?? throw new ArgumentNullException(nameof(source)), dataObject);
4244
}
4345

4446
/// <summary>
@@ -48,9 +50,9 @@ protected bool ToDataObject(TPeer source, TDataObject dataObject)
4850
/// <param name="target"></param>
4951
/// <returns></returns>
5052
/// <exception cref="ArgumentNullException"></exception>
51-
protected bool FromDataObject(TDataObject dataObject, TPeer target)
53+
protected bool FromDto(TDto dataObject, TPeer target)
5254
{
53-
return _mappings.FromDataObject(dataObject ?? throw new ArgumentNullException(nameof(dataObject)),
55+
return _mappings.FromDto(dataObject ?? throw new ArgumentNullException(nameof(dataObject)),
5456
target);
5557
}
5658
}

PG.Commons/PG.Commons/Data/DataObjectMappings.cs renamed to PG.Commons/PG.Commons/Data/DataTransferObjectMappings.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ namespace PG.Commons.Data;
77
/// <summary>
88
/// Data mappings.
99
/// </summary>
10-
/// <typeparam name="TDataObject"></typeparam>
10+
/// <typeparam name="TDto"></typeparam>
1111
/// <typeparam name="TPeer"></typeparam>
12-
public class DataObjectMappings<TDataObject, TPeer>
12+
public class DataTransferObjectMappings<TDto, TPeer>
1313
{
14-
private List<IDataObjectMapping<TDataObject, TPeer>> Mappings { get; } = new();
14+
private List<IDataTransferObjectMapping<TDto, TPeer>> Mappings { get; } = new();
1515

1616
// ReSharper disable once HeapView.ClosureAllocation
17-
internal bool ToDataObject([DisallowNull] TPeer source, TDataObject dataObject)
17+
internal bool ToDto([DisallowNull] TPeer source, TDto dataObject)
1818
{
1919
if (source == null) throw new ArgumentNullException(nameof(source));
2020
try
2121
{
2222
// ReSharper disable once HeapView.DelegateAllocation
23-
Mappings.ForEach(m => m.ToDataObject(source, dataObject));
23+
Mappings.ForEach(m => m.ToDto(source, dataObject));
2424
}
2525
catch (Exception)
2626
{
@@ -31,13 +31,13 @@ internal bool ToDataObject([DisallowNull] TPeer source, TDataObject dataObject)
3131
}
3232

3333
// ReSharper disable once HeapView.ClosureAllocation
34-
internal bool FromDataObject([DisallowNull] TDataObject dataObject, TPeer target)
34+
internal bool FromDto([DisallowNull] TDto dataObject, TPeer target)
3535
{
3636
if (dataObject == null) throw new ArgumentNullException(nameof(dataObject));
3737
try
3838
{
3939
// ReSharper disable once HeapView.DelegateAllocation
40-
Mappings.ForEach(m => m.FromDataObject(dataObject, target));
40+
Mappings.ForEach(m => m.FromDto(dataObject, target));
4141
}
4242
catch (Exception)
4343
{
@@ -56,12 +56,13 @@ internal bool FromDataObject([DisallowNull] TDataObject dataObject, TPeer target
5656
/// <param name="peerValueSetter"></param>
5757
/// <typeparam name="TValue"></typeparam>
5858
/// <returns></returns>
59-
public DataObjectMappings<TDataObject, TPeer> With<TValue>(Func<TDataObject, TValue> dataObjectValueGetter,
60-
Action<TDataObject, TValue> dataObjectValueSetter,
59+
public DataTransferObjectMappings<TDto, TPeer> With<TValue>(Func<TDto, TValue> dataObjectValueGetter,
60+
Action<TDto, TValue> dataObjectValueSetter,
6161
Func<TPeer, TValue> peerValueGetter, Action<TPeer, TValue> peerValueSetter)
6262
{
6363
// ReSharper disable once HeapView.ObjectAllocation.Evident
64-
Mappings.Add(new DataObjectMapping<TDataObject, TPeer, TValue>(dataObjectValueGetter, dataObjectValueSetter,
64+
Mappings.Add(new DataTransferTransferObjectMapping<TDto, TPeer, TValue>(dataObjectValueGetter,
65+
dataObjectValueSetter,
6566
peerValueGetter, peerValueSetter));
6667
return this;
6768
}

PG.Commons/PG.Commons/Data/DataObjectMapping.cs renamed to PG.Commons/PG.Commons/Data/DataTransferTransferObjectMapping.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
namespace PG.Commons.Data;
44

5-
internal class DataObjectMapping<TDataObject, TPeer, TValue>(
6-
Func<TDataObject, TValue> dataObjectValueGetter,
7-
Action<TDataObject, TValue> dataObjectValueSetter,
5+
internal class DataTransferTransferObjectMapping<TDto, TPeer, TValue>(
6+
Func<TDto, TValue> dataObjectValueGetter,
7+
Action<TDto, TValue> dataObjectValueSetter,
88
Func<TPeer, TValue> peerValueGetter,
99
Action<TPeer, TValue> peerValueSetter)
10-
: IDataObjectMapping<TDataObject, TPeer>
10+
: IDataTransferObjectMapping<TDto, TPeer>
1111
{
12-
private Func<TDataObject, TValue> DataObjectValueGetter { get; } = dataObjectValueGetter;
13-
private Action<TDataObject, TValue> DataObjectValueSetter { get; } = dataObjectValueSetter;
12+
private Func<TDto, TValue> DataObjectValueGetter { get; } = dataObjectValueGetter;
13+
private Action<TDto, TValue> DataObjectValueSetter { get; } = dataObjectValueSetter;
1414
private Func<TPeer, TValue> PeerValueGetter { get; } = peerValueGetter;
1515
private Action<TPeer, TValue> PeerValueSetter { get; } = peerValueSetter;
1616

17-
public void ToDataObject(TPeer source, TDataObject dataObject)
17+
public void ToDto(TPeer source, TDto dataObject)
1818
{
1919
if (source == null) throw new ArgumentNullException(nameof(source));
2020
if (dataObject == null) throw new ArgumentNullException(nameof(dataObject));
@@ -23,7 +23,7 @@ public void ToDataObject(TPeer source, TDataObject dataObject)
2323
DataObjectValueSetter.Invoke(dataObject, value);
2424
}
2525

26-
public void FromDataObject(TDataObject dataObject, TPeer target)
26+
public void FromDto(TDto dataObject, TPeer target)
2727
{
2828
if (target == null) throw new ArgumentNullException(nameof(target));
2929
if (dataObject == null) throw new ArgumentNullException(nameof(dataObject));

PG.Commons/PG.Commons/Data/IDataObjectMapping.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace PG.Commons.Data;
2+
3+
internal interface IDataTransferObjectMapping<in TDataObject, in TPeer>
4+
{
5+
internal void ToDto(TPeer source, TDataObject dataObject);
6+
7+
internal void FromDto(TDataObject dataObject, TPeer target);
8+
}

0 commit comments

Comments
 (0)