File tree 4 files changed +31
-28
lines changed
src/SmartCode/Configuration/ConfigBuilders
4 files changed +31
-28
lines changed Original file line number Diff line number Diff line change 2
2
<PropertyGroup >
3
3
<VersionMajor >2</VersionMajor >
4
4
<VersionMinor >2</VersionMinor >
5
- <VersionPatch >53 </VersionPatch >
5
+ <VersionPatch >55 </VersionPatch >
6
6
<VersionPrefix >$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix >
7
7
</PropertyGroup >
8
8
</Project >
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . IO ;
3
4
using System . Text ;
4
5
using System . Threading . Tasks ;
5
6
6
7
namespace SmartCode . Configuration . ConfigBuilders
7
8
{
8
9
public abstract class ConfigBuilder : IConfigBuilder
9
10
{
10
- protected Project Project { get ; set ; }
11
- public abstract Project Build ( ) ;
11
+ public string ConfigPath { get ; }
12
+ public Project Project { get ; set ; }
12
13
13
- protected void InitDefault ( )
14
+ protected ConfigBuilder ( string configPath )
15
+ {
16
+ ConfigPath = configPath ;
17
+ }
18
+ public Project Build ( )
19
+ {
20
+ using ( StreamReader configStream = new StreamReader ( ConfigPath ) )
21
+ {
22
+ var jsonConfigStr = configStream . ReadToEnd ( ) ;
23
+ Project = Deserialize ( jsonConfigStr ) ;
24
+ }
25
+ InitDefault ( ) ;
26
+ return Project ;
27
+ }
28
+
29
+ protected abstract Project Deserialize ( string content ) ;
30
+
31
+ private void InitDefault ( )
14
32
{
15
33
if ( Project . Output != null )
16
34
{
Original file line number Diff line number Diff line change 4
4
using System . Text ;
5
5
using System . Threading . Tasks ;
6
6
using Newtonsoft . Json ;
7
+
7
8
namespace SmartCode . Configuration . ConfigBuilders
8
9
{
9
10
public class JsonBuilder : ConfigBuilder
10
11
{
11
- private readonly string _configPath ;
12
-
13
- public JsonBuilder ( string configPath )
12
+ public JsonBuilder ( string configPath ) : base ( configPath )
14
13
{
15
- _configPath = configPath ;
16
14
}
17
- public override Project Build ( )
15
+
16
+ protected override Project Deserialize ( string content )
18
17
{
19
- using ( StreamReader configStream = new StreamReader ( _configPath ) )
20
- {
21
- var jsonConfigStr = configStream . ReadToEnd ( ) ;
22
- Project = JsonConvert . DeserializeObject < Project > ( jsonConfigStr ) ;
23
- }
24
- InitDefault ( ) ;
25
- return Project ;
18
+ return JsonConvert . DeserializeObject < Project > ( content ) ;
26
19
}
27
20
}
28
- }
21
+ }
Original file line number Diff line number Diff line change @@ -10,23 +10,15 @@ namespace SmartCode.Configuration.ConfigBuilders
10
10
{
11
11
public class YamlBuilder : ConfigBuilder
12
12
{
13
- private readonly string _configPath ;
14
13
private readonly IDeserializer _deserializer ;
15
- public YamlBuilder ( string configPath )
14
+ public YamlBuilder ( string configPath ) : base ( configPath )
16
15
{
17
- _configPath = configPath ;
18
16
_deserializer = new DeserializerBuilder ( ) . Build ( ) ;
19
17
}
20
18
21
- public override Project Build ( )
19
+ protected override Project Deserialize ( string content )
22
20
{
23
- using ( StreamReader configStream = new StreamReader ( _configPath ) )
24
- {
25
- var yamlConfigStr = configStream . ReadToEnd ( ) ;
26
- Project = _deserializer . Deserialize < Project > ( yamlConfigStr ) ;
27
- }
28
- InitDefault ( ) ;
29
- return Project ;
21
+ return _deserializer . Deserialize < Project > ( content ) ;
30
22
}
31
23
}
32
24
}
You can’t perform that action at this time.
0 commit comments