Skip to content

Commit 909c598

Browse files
author
sam.gerene
committed
[Improve] code quaility as per SQ suggestions
1 parent 5812a72 commit 909c598

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

SysML2.NET.CodeGenerator/Extensions/EcoreExtensions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static class EcoreExtensions
3737
/// <summary>
3838
/// A mapping of the known SysML value types to C# types
3939
/// </summary>
40-
public static readonly Dictionary<string, string> TypeMapping = new Dictionary<string, string>
40+
private static readonly Dictionary<string, string> TypeMapping = new Dictionary<string, string>
4141
{
4242
{"Boolean", "bool"},
4343
{"Integer", "int"},
@@ -92,10 +92,7 @@ public static bool QueryIsEnum(this EStructuralFeature eStructuralFeature)
9292
{
9393
if (eStructuralFeature is EAttribute eAttribute)
9494
{
95-
if (eAttribute.EType is EEnum)
96-
{
97-
return true;
98-
}
95+
return eAttribute.EType is EEnum;
9996
}
10097

10198
return false;

SysML2.NET.CodeGenerator/Generators/HandleBarsGenerators/DtoSerializerGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public async Task GenerateSerializationProvider(EPackage package, DirectoryInfo
9898
{
9999
var template = this.Templates["dto-serialization-provider-template"];
100100

101-
var eClasses = package.EClassifiers.OfType<EClass>().Where(x => !x.Abstract).OrderBy(x => x.Name).ToList().ToList();
101+
var eClasses = package.EClassifiers.OfType<EClass>().Where(x => !x.Abstract).OrderBy(x => x.Name).ToList();
102102

103103
var generatedSerializationProvider = template(eClasses);
104104

SysML2.NET.Serializer.Json.Tests/SerializerTestFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void Verify_that_Elements_can_be_serialized()
7373
var stream = new MemoryStream();
7474
var jsonWriterOptions = new JsonWriterOptions { Indented = true };
7575

76-
this.serializer.Serialize(elements, SerializationModeKind.JSON, stream, jsonWriterOptions);
76+
Assert.That(() => this.serializer.Serialize(elements, SerializationModeKind.JSON, stream, jsonWriterOptions), Throws.Nothing); ;
7777

7878
string json = Encoding.UTF8.GetString(stream.ToArray());
7979
Console.WriteLine(json);

SysML2.NET.Serializer.Json/DeSerializer.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace SysML2.NET.Serializer.Json
2222
{
2323
using System.Collections.Generic;
24+
using System.Diagnostics;
2425
using System.IO;
2526
using System.Text.Json;
2627

@@ -72,15 +73,17 @@ public DeSerializer(ILoggerFactory loggerFactory = null)
7273
/// </returns>
7374
public IEnumerable<IElement> DeSerialize(Stream stream, SerializationModeKind serializationModeKind)
7475
{
76+
var sw = Stopwatch.StartNew();
77+
7578
var result = new List<IElement>();
7679

77-
using (JsonDocument document = JsonDocument.Parse(stream))
80+
using (var document = JsonDocument.Parse(stream))
7881
{
79-
JsonElement root = document.RootElement;
82+
var root = document.RootElement;
8083

81-
foreach (JsonElement jsonElement in root.EnumerateArray())
84+
foreach (var jsonElement in root.EnumerateArray())
8285
{
83-
if (jsonElement.TryGetProperty("@type", out JsonElement typeElement))
86+
if (jsonElement.TryGetProperty("@type", out var typeElement))
8487
{
8588
var typeName = typeElement.GetString();
8689

@@ -91,6 +94,8 @@ public IEnumerable<IElement> DeSerialize(Stream stream, SerializationModeKind se
9194
}
9295
}
9396

97+
this.logger.LogInformation($"stream deserialized in {sw.ElapsedMilliseconds} [ms]");
98+
9499
return result;
95100
}
96101
}

0 commit comments

Comments
 (0)