File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
algorithm_exercises_csharp_test/src/lib Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ namespace algorithm_exercises_csharp . hackerrank . interview_preparation_kit ;
2
+
3
+ using System . Reflection ;
4
+ using System . Text ;
5
+ using Newtonsoft . Json ;
6
+
7
+ public static class JsonLoader
8
+ {
9
+ public static T ? resourceLoad < T > ( string _path )
10
+ {
11
+ string path = _path ;
12
+ path = path . Replace ( '/' , '.' ) ;
13
+ path = path . Replace ( '\\ ' , '.' ) ;
14
+
15
+ var info = Assembly . GetExecutingAssembly ( ) . GetName ( ) ;
16
+ var name = info . Name ;
17
+
18
+ path = $ "{ name } .Resources.{ path } ";
19
+ Log . debug ( $ "Loading JSON from: { path } ") ;
20
+
21
+ using var stream = Assembly
22
+ . GetExecutingAssembly ( )
23
+ . GetManifestResourceStream ( $ "{ path } ") ! ;
24
+
25
+
26
+ using var streamReader = new StreamReader ( stream , Encoding . UTF8 ) ;
27
+
28
+ return JsonConvert . DeserializeObject < T > (
29
+ streamReader . ReadToEnd ( )
30
+ ) ;
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments