Skip to content

Instantly share code, notes, and snippets.

@FransBouma
Created March 24, 2014 08:53
Show Gist options
  • Save FransBouma/9736633 to your computer and use it in GitHub Desktop.
Save FransBouma/9736633 to your computer and use it in GitHub Desktop.
Even with 20+ years of development experience, Monday mornings are hard...
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;
@FransBouma
Copy link
Author

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 ;)

@laurenceabas
Copy link

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