Skip to content

Commit 625ebc4

Browse files
author
Gonzalo Diaz
committed
LIB: New JSON Load method to load data from JSON string.
1 parent ca0139e commit 625ebc4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/algorithm_exercises_csharp_test/lib/JsonLoader.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ namespace algorithm_exercises_csharp_test.lib;
33

44
using System.Reflection;
55
using System.Text;
6+
using System;
7+
68
using Newtonsoft.Json;
79

810
public static class JsonLoader
911
{
10-
public static T? resourceLoad<T>(string _path)
12+
public static T? resourceLoad<T>(string path)
1113
{
12-
string path = _path;
14+
ArgumentNullException.ThrowIfNull(path);
15+
1316
path = path.Replace('/', '.');
1417
path = path.Replace('\\', '.');
1518

@@ -23,11 +26,15 @@ public static class JsonLoader
2326
.GetExecutingAssembly()
2427
.GetManifestResourceStream($"{path}")!;
2528

26-
2729
using var streamReader = new StreamReader(stream, Encoding.UTF8);
2830

2931
return JsonConvert.DeserializeObject<T>(
3032
streamReader.ReadToEnd()
3133
);
3234
}
35+
36+
public static T? stringLoad<T>(string json)
37+
{
38+
return JsonConvert.DeserializeObject<T>(json);
39+
}
3340
}

0 commit comments

Comments
 (0)