Created
March 24, 2014 08:53
-
-
Save FransBouma/9736633 to your computer and use it in GitHub Desktop.
Even with 20+ years of development experience, Monday mornings are hard...
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
object newValueInType = newValue; | |
string newValueAsString = newValue as string; | |
if(type == typeof(DateTimeOffset)) | |
{ | |
newValueInType = DateTimeOffset.Parse(newValueAsString); | |
} | |
if(type == typeof(Guid)) | |
{ | |
newValueInType = Guid.Parse(newValueAsString); | |
} | |
if(type == typeof(TimeSpan)) | |
{ | |
newValueInType = TimeSpan.Parse(newValueAsString); | |
} | |
else | |
{ | |
newValueInType = Convert.ChangeType(newValue, type); | |
} | |
_defaultsPerType[type] = newValueInType; |
Cant agree more with you about Monday.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code has a silly bug of the type one only writes on Monday mornings... I know the code is not stellar, type related code is always a mess as there's no real solid way to test for types other than with Type.GetTypeCode which returns an enum which doesn't contain some value types like Guid ;)