-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added automatic conversion of enum types without explicitly having to…
… specify a converter for them.
- Loading branch information
Ruben Martinez
committed
Jul 2, 2019
1 parent
64c1fb4
commit 3454080
Showing
6 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
DotNet.MultiSourceConfiguration/Implementation/EnumConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using MultiSourceConfiguration.Config.Implementation; | ||
using System; | ||
|
||
namespace DotNet.MultiSourceConfiguration.Implementation | ||
{ | ||
class EnumConverter : UnifiedConverter | ||
{ | ||
private Type type; | ||
|
||
public EnumConverter(Type type) | ||
{ | ||
this.type = type; | ||
} | ||
|
||
public override Type Type => type; | ||
|
||
public override object FromString(string value) | ||
{ | ||
return Enum.Parse(type, value); | ||
} | ||
|
||
public override object GetDefaultValue() | ||
{ | ||
return Enum.GetValues(type).GetValue(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters