Skip to content

Commit 75c38c5

Browse files
committed
Improved json parsing with the 'SourcesToJson(...)' method by using the 'SourceModel' class, that is intended for json parsing; Removed the Json attributes from the 'WinGetSource' class
1 parent 3a9f98a commit 75c38c5

4 files changed

Lines changed: 90 additions & 21 deletions

File tree

‎src/WGet.NET/Components/WinGetSourceManager.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,14 @@ public string SourcesToJson(IEnumerable<WinGetSource> sources)
10361036
{
10371037
ArgsHelper.ThrowIfObjectIsNull(sources, "sources");
10381038

1039-
return JsonHelper.GetJson(sources);
1039+
// Create source models for json parsing
1040+
List<SourceModel> models = new List<SourceModel>();
1041+
foreach (WinGetSource source in sources)
1042+
{
1043+
models.Add(SourceModel.FromWinGetSource(source));
1044+
}
1045+
1046+
return JsonHelper.GetJson(models);
10401047
}
10411048
//---------------------------------------------------------------------------------------------
10421049
}

‎src/WGet.NET/Data/WinGetSource.cs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
// https://github.com/basicx-StrgV/ //
44
//--------------------------------------------------//
55
using System;
6-
#if NETCOREAPP3_1_OR_GREATER
7-
using System.Text.Json.Serialization;
8-
#elif NETSTANDARD2_0
9-
using Newtonsoft.Json;
10-
#endif
116
using WGetNET.Models;
127
using WGetNET.Helper;
138

@@ -74,7 +69,6 @@ public string Identifier
7469
}
7570

7671
/// <inheritdoc/>
77-
[JsonIgnore]
7872
public bool IsEmpty
7973
{
8074
get

‎src/WGet.NET/Models/SourceModel.cs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,24 @@ internal SourceModel()
132132
{
133133
// Empty constructor for json parsing.
134134
}
135+
136+
/// <summary>
137+
/// Creates a <see cref="WGetNET.Models.SourceModel"/> instance from a <see cref="WGetNET.WinGetSource"/> instance.
138+
/// </summary>
139+
/// <param name="source">The <see cref="WGetNET.WinGetSource"/> instance.</param>
140+
/// <returns>
141+
/// The created <see cref="WGetNET.Models.SourceModel"/> instance.
142+
/// </returns>
143+
public static SourceModel FromWinGetSource(WinGetSource source)
144+
{
145+
return new SourceModel()
146+
{
147+
Name = source.Name,
148+
Arg = source.Arg,
149+
Type = source.Type,
150+
Data = source.Data,
151+
Identifier = source.Identifier
152+
};
153+
}
135154
}
136155
}

‎src/WGet.NET/XmlDocumentation/WGet.NET.xml‎

Lines changed: 63 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)