-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to be set by command line
- Loading branch information
Showing
4 changed files
with
42 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
namespace Rnwood.Smtp4dev.Server.Settings | ||
using System; | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using System.Linq; | ||
|
||
namespace Rnwood.Smtp4dev.Server.Settings | ||
{ | ||
[TypeConverter(typeof(UserFromStringConverter))] | ||
public class User | ||
{ | ||
public string Username { get; set; } | ||
public string Password { get; set; } | ||
} | ||
|
||
public class UserFromStringConverter : TypeConverter | ||
{ | ||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) | ||
{ | ||
return sourceType == typeof(string); | ||
} | ||
|
||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) | ||
{ | ||
string stringValue = value as string; | ||
|
||
string[] values = stringValue.Split('=', 2); | ||
|
||
return new User { Username = values[0], Password = values.Last() ?? "" }; | ||
} | ||
} | ||
} |