Skip to content

Commit 26bfbee

Browse files
author
samatrhea
committed
[Add] ToDto method to poco extensions; fixes #19
1 parent db94881 commit 26bfbee

File tree

176 files changed

+6069
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+6069
-45
lines changed

SysML2.NET.CodeGenerator.Tests/Expected/AutoGenPocoExtension/AnnotatingElementExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,32 @@ public static void UpdateReferenceProperties(this Core.POCO.AnnotatingElement po
156156
}
157157

158158
}
159+
160+
/// <summary>
161+
/// Creates a <see cref="Core.DTO.AnnotatingElement"/> based on the provided POCO
162+
/// </summary>
163+
/// <param name="poco">
164+
/// The subject <see cref="Core.POCO.AnnotatingElement"/> from which a DTO is to be created
165+
/// </param>
166+
/// <returns>
167+
/// An instance of <see cref="Core.POCO.AnnotatingElement"/>
168+
/// </returns>
169+
public static Core.DTO.AnnotatingElement ToDto(this Core.POCO.AnnotatingElement poco)
170+
{
171+
var dto = new Core.DTO.AnnotatingElement();
172+
173+
dto.Id = poco.Id;
174+
dto.AliasIds = poco.AliasIds;
175+
dto.Annotation = poco.Annotation.Select(x => x.Id).ToList();
176+
dto.DeclaredName = poco.DeclaredName;
177+
dto.DeclaredShortName = poco.DeclaredShortName;
178+
dto.ElementId = poco.ElementId;
179+
dto.IsImpliedIncluded = poco.IsImpliedIncluded;
180+
dto.OwnedRelationship = poco.OwnedRelationship.Select(x => x.Id).ToList();
181+
dto.OwningRelationship = poco.OwningRelationship?.Id;
182+
183+
return dto;
184+
}
159185
}
160186
}
161187

SysML2.NET.CodeGenerator.Tests/Expected/AutoGenPocoExtension/AnnotationExtensions.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,38 @@ public static void UpdateReferenceProperties(this Core.POCO.Annotation poco, Cor
216216
}
217217

218218
}
219+
220+
/// <summary>
221+
/// Creates a <see cref="Core.DTO.Annotation"/> based on the provided POCO
222+
/// </summary>
223+
/// <param name="poco">
224+
/// The subject <see cref="Core.POCO.Annotation"/> from which a DTO is to be created
225+
/// </param>
226+
/// <returns>
227+
/// An instance of <see cref="Core.POCO.Annotation"/>
228+
/// </returns>
229+
public static Core.DTO.Annotation ToDto(this Core.POCO.Annotation poco)
230+
{
231+
var dto = new Core.DTO.Annotation();
232+
233+
dto.Id = poco.Id;
234+
dto.AliasIds = poco.AliasIds;
235+
dto.AnnotatedElement = poco.AnnotatedElement.Id;
236+
dto.AnnotatingElement = poco.AnnotatingElement.Id;
237+
dto.DeclaredName = poco.DeclaredName;
238+
dto.DeclaredShortName = poco.DeclaredShortName;
239+
dto.ElementId = poco.ElementId;
240+
dto.IsImplied = poco.IsImplied;
241+
dto.IsImpliedIncluded = poco.IsImpliedIncluded;
242+
dto.OwnedRelatedElement = poco.OwnedRelatedElement.Select(x => x.Id).ToList();
243+
dto.OwnedRelationship = poco.OwnedRelationship.Select(x => x.Id).ToList();
244+
dto.OwningRelatedElement = poco.OwningRelatedElement?.Id;
245+
dto.OwningRelationship = poco.OwningRelationship?.Id;
246+
dto.Source = poco.Source.Select(x => x.Id).ToList();
247+
dto.Target = poco.Target.Select(x => x.Id).ToList();
248+
249+
return dto;
250+
}
219251
}
220252
}
221253

SysML2.NET.CodeGenerator.Tests/Expected/AutoGenPocoExtension/CommentExtensions.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,34 @@ public static void UpdateReferenceProperties(this Core.POCO.Comment poco, Core.D
160160
}
161161

162162
}
163+
164+
/// <summary>
165+
/// Creates a <see cref="Core.DTO.Comment"/> based on the provided POCO
166+
/// </summary>
167+
/// <param name="poco">
168+
/// The subject <see cref="Core.POCO.Comment"/> from which a DTO is to be created
169+
/// </param>
170+
/// <returns>
171+
/// An instance of <see cref="Core.POCO.Comment"/>
172+
/// </returns>
173+
public static Core.DTO.Comment ToDto(this Core.POCO.Comment poco)
174+
{
175+
var dto = new Core.DTO.Comment();
176+
177+
dto.Id = poco.Id;
178+
dto.AliasIds = poco.AliasIds;
179+
dto.Annotation = poco.Annotation.Select(x => x.Id).ToList();
180+
dto.Body = poco.Body;
181+
dto.DeclaredName = poco.DeclaredName;
182+
dto.DeclaredShortName = poco.DeclaredShortName;
183+
dto.ElementId = poco.ElementId;
184+
dto.IsImpliedIncluded = poco.IsImpliedIncluded;
185+
dto.Locale = poco.Locale;
186+
dto.OwnedRelationship = poco.OwnedRelationship.Select(x => x.Id).ToList();
187+
dto.OwningRelationship = poco.OwningRelationship?.Id;
188+
189+
return dto;
190+
}
163191
}
164192
}
165193

SysML2.NET.CodeGenerator.Tests/Expected/AutoGenPocoExtension/ConnectorExtensions.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,47 @@ public static void UpdateReferenceProperties(this Core.POCO.Connector poco, Core
220220
}
221221

222222
}
223+
224+
/// <summary>
225+
/// Creates a <see cref="Core.DTO.Connector"/> based on the provided POCO
226+
/// </summary>
227+
/// <param name="poco">
228+
/// The subject <see cref="Core.POCO.Connector"/> from which a DTO is to be created
229+
/// </param>
230+
/// <returns>
231+
/// An instance of <see cref="Core.POCO.Connector"/>
232+
/// </returns>
233+
public static Core.DTO.Connector ToDto(this Core.POCO.Connector poco)
234+
{
235+
var dto = new Core.DTO.Connector();
236+
237+
dto.Id = poco.Id;
238+
dto.AliasIds = poco.AliasIds;
239+
dto.DeclaredName = poco.DeclaredName;
240+
dto.DeclaredShortName = poco.DeclaredShortName;
241+
dto.Direction = poco.Direction;
242+
dto.ElementId = poco.ElementId;
243+
dto.IsAbstract = poco.IsAbstract;
244+
dto.IsComposite = poco.IsComposite;
245+
dto.IsDerived = poco.IsDerived;
246+
dto.IsDirected = poco.IsDirected;
247+
dto.IsEnd = poco.IsEnd;
248+
dto.IsImplied = poco.IsImplied;
249+
dto.IsImpliedIncluded = poco.IsImpliedIncluded;
250+
dto.IsOrdered = poco.IsOrdered;
251+
dto.IsPortion = poco.IsPortion;
252+
dto.IsReadOnly = poco.IsReadOnly;
253+
dto.IsSufficient = poco.IsSufficient;
254+
dto.IsUnique = poco.IsUnique;
255+
dto.OwnedRelatedElement = poco.OwnedRelatedElement.Select(x => x.Id).ToList();
256+
dto.OwnedRelationship = poco.OwnedRelationship.Select(x => x.Id).ToList();
257+
dto.OwningRelatedElement = poco.OwningRelatedElement?.Id;
258+
dto.OwningRelationship = poco.OwningRelationship?.Id;
259+
dto.Source = poco.Source.Select(x => x.Id).ToList();
260+
dto.Target = poco.Target.Select(x => x.Id).ToList();
261+
262+
return dto;
263+
}
223264
}
224265
}
225266

SysML2.NET.CodeGenerator.Tests/Expected/AutoGenPocoExtension/DependencyExtensions.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,38 @@ public static void UpdateReferenceProperties(this Core.POCO.Dependency poco, Cor
228228
}
229229

230230
}
231+
232+
/// <summary>
233+
/// Creates a <see cref="Core.DTO.Dependency"/> based on the provided POCO
234+
/// </summary>
235+
/// <param name="poco">
236+
/// The subject <see cref="Core.POCO.Dependency"/> from which a DTO is to be created
237+
/// </param>
238+
/// <returns>
239+
/// An instance of <see cref="Core.POCO.Dependency"/>
240+
/// </returns>
241+
public static Core.DTO.Dependency ToDto(this Core.POCO.Dependency poco)
242+
{
243+
var dto = new Core.DTO.Dependency();
244+
245+
dto.Id = poco.Id;
246+
dto.AliasIds = poco.AliasIds;
247+
dto.Client = poco.Client.Select(x => x.Id).ToList();
248+
dto.DeclaredName = poco.DeclaredName;
249+
dto.DeclaredShortName = poco.DeclaredShortName;
250+
dto.ElementId = poco.ElementId;
251+
dto.IsImplied = poco.IsImplied;
252+
dto.IsImpliedIncluded = poco.IsImpliedIncluded;
253+
dto.OwnedRelatedElement = poco.OwnedRelatedElement.Select(x => x.Id).ToList();
254+
dto.OwnedRelationship = poco.OwnedRelationship.Select(x => x.Id).ToList();
255+
dto.OwningRelatedElement = poco.OwningRelatedElement?.Id;
256+
dto.OwningRelationship = poco.OwningRelationship?.Id;
257+
dto.Source = poco.Source.Select(x => x.Id).ToList();
258+
dto.Supplier = poco.Supplier.Select(x => x.Id).ToList();
259+
dto.Target = poco.Target.Select(x => x.Id).ToList();
260+
261+
return dto;
262+
}
231263
}
232264
}
233265

SysML2.NET.CodeGenerator.Tests/Expected/AutoGenPocoExtension/ElementExtensions.cs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
namespace SysML2.NET.Dal
2626
{
27-
using System;
28-
using System.Collections.Concurrent;
29-
using System.Collections.Generic;
30-
31-
/// <summary>
32-
/// A static class that provides extension methods for the <see cref="Core.POCO.IElement"/> class
33-
/// </summary>
34-
public static class ElementExtensions
35-
{
27+
using System;
28+
using System.Collections.Concurrent;
29+
using System.Collections.Generic;
30+
31+
/// <summary>
32+
/// A static class that provides extension methods for the <see cref="Core.POCO.IElement"/> class
33+
/// </summary>
34+
public static class ElementExtensions
35+
{
3636
/// <summary>
3737
/// Updates the value properties of the <see cref="Core.POCO.IElement"/> by setting the value equal to that of the dto.
3838
/// Removes deleted objects from the reference properties and returns the unique identifiers
@@ -51,25 +51,25 @@ public static class ElementExtensions
5151
/// Thrown when the <paramref name="poco"/> or <paramref name="dto"/> is null
5252
/// </exception>
5353
public static IEnumerable<Guid> UpdateValueAndRemoveDeletedReferenceProperties(this Core.POCO.IElement poco, Core.DTO.IElement dto)
54-
{
55-
if (poco == null)
56-
{
57-
throw new ArgumentNullException(nameof(poco), $"the {nameof(poco)} may not be null");
58-
}
54+
{
55+
if (poco == null)
56+
{
57+
throw new ArgumentNullException(nameof(poco), $"the {nameof(poco)} may not be null");
58+
}
5959

60-
if (dto == null)
61-
{
62-
throw new ArgumentNullException(nameof(dto), $"the {nameof(dto)} may not be null");
63-
}
60+
if (dto == null)
61+
{
62+
throw new ArgumentNullException(nameof(dto), $"the {nameof(dto)} may not be null");
63+
}
6464

65-
switch (poco)
66-
{
67-
case Core.POCO.PartDefinition partDefinition:
68-
return partDefinition.UpdateValueAndRemoveDeletedReferenceProperties(dto);
69-
default:
70-
throw new NotSupportedException($"{poco.GetType().Name} not yet supported");
71-
}
72-
}
65+
switch (poco)
66+
{
67+
case Core.POCO.PartDefinition partDefinition:
68+
return partDefinition.UpdateValueAndRemoveDeletedReferenceProperties(dto);
69+
default:
70+
throw new NotSupportedException($"{poco.GetType().Name} not yet supported");
71+
}
72+
}
7373

7474
/// <summary>
7575
/// Updates the Reference properties of the <see cref="Core.POCO.IElement"/> using the data (identifiers) encapsulated in the DTO
@@ -87,24 +87,24 @@ public static IEnumerable<Guid> UpdateValueAndRemoveDeletedReferenceProperties(t
8787
/// </param>
8888
/// <exception cref="ArgumentNullException"></exception>
8989
public static void UpdateReferenceProperties(this Core.POCO.IElement poco, Core.DTO.IElement dto, ConcurrentDictionary<Guid, Lazy<Core.POCO.IElement>> cache)
90-
{
91-
if (poco == null)
92-
{
93-
throw new ArgumentNullException(nameof(poco), $"the {nameof(poco)} may not be null");
94-
}
90+
{
91+
if (poco == null)
92+
{
93+
throw new ArgumentNullException(nameof(poco), $"the {nameof(poco)} may not be null");
94+
}
9595

96-
if (dto == null)
97-
{
98-
throw new ArgumentNullException(nameof(dto), $"the {nameof(dto)} may not be null");
99-
}
96+
if (dto == null)
97+
{
98+
throw new ArgumentNullException(nameof(dto), $"the {nameof(dto)} may not be null");
99+
}
100100

101-
if (cache == null)
102-
{
103-
throw new ArgumentNullException(nameof(cache), $"the {nameof(cache)} may not be null");
104-
}
101+
if (cache == null)
102+
{
103+
throw new ArgumentNullException(nameof(cache), $"the {nameof(cache)} may not be null");
104+
}
105105

106-
switch (poco)
107-
{
106+
switch (poco)
107+
{
108108
case Core.POCO.AnnotatingElement annotatingElement:
109109
annotatingElement.UpdateReferenceProperties((Core.DTO.AnnotatingElement)dto, cache);
110110
break;
@@ -133,10 +133,10 @@ public static void UpdateReferenceProperties(this Core.POCO.IElement poco, Core.
133133
literalRational.UpdateReferenceProperties((Core.DTO.LiteralRational)dto, cache);
134134
break;
135135
default:
136-
throw new NotSupportedException($"{poco.GetType().Name} not yet supported");
137-
}
138-
}
139-
}
136+
throw new NotSupportedException($"{poco.GetType().Name} not yet supported");
137+
}
138+
}
139+
}
140140
}
141141

142142
// ------------------------------------------------------------------------------------------------

SysML2.NET.CodeGenerator.Tests/Expected/AutoGenPocoExtension/FeatureExtensions.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,41 @@ public static void UpdateReferenceProperties(this Core.POCO.Feature poco, Core.D
161161
}
162162

163163
}
164+
165+
/// <summary>
166+
/// Creates a <see cref="Core.DTO.Feature"/> based on the provided POCO
167+
/// </summary>
168+
/// <param name="poco">
169+
/// The subject <see cref="Core.POCO.Feature"/> from which a DTO is to be created
170+
/// </param>
171+
/// <returns>
172+
/// An instance of <see cref="Core.POCO.Feature"/>
173+
/// </returns>
174+
public static Core.DTO.Feature ToDto(this Core.POCO.Feature poco)
175+
{
176+
var dto = new Core.DTO.Feature();
177+
178+
dto.Id = poco.Id;
179+
dto.AliasIds = poco.AliasIds;
180+
dto.DeclaredName = poco.DeclaredName;
181+
dto.DeclaredShortName = poco.DeclaredShortName;
182+
dto.Direction = poco.Direction;
183+
dto.ElementId = poco.ElementId;
184+
dto.IsAbstract = poco.IsAbstract;
185+
dto.IsComposite = poco.IsComposite;
186+
dto.IsDerived = poco.IsDerived;
187+
dto.IsEnd = poco.IsEnd;
188+
dto.IsImpliedIncluded = poco.IsImpliedIncluded;
189+
dto.IsOrdered = poco.IsOrdered;
190+
dto.IsPortion = poco.IsPortion;
191+
dto.IsReadOnly = poco.IsReadOnly;
192+
dto.IsSufficient = poco.IsSufficient;
193+
dto.IsUnique = poco.IsUnique;
194+
dto.OwnedRelationship = poco.OwnedRelationship.Select(x => x.Id).ToList();
195+
dto.OwningRelationship = poco.OwningRelationship?.Id;
196+
197+
return dto;
198+
}
164199
}
165200
}
166201

0 commit comments

Comments
 (0)