Skip to content

Commit 42f651e

Browse files
committed
Solves Casting String to GUID
When retrieving a string from the database and trying to map it to a GUID the safe convert would throw an exception and return null. This allows for converting strings to GUIDS if possible.
1 parent 65baeba commit 42f651e

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Simple.Data/PropertySetterBuilder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.ComponentModel;
2+
13
namespace Simple.Data
24
{
35
using System;
@@ -357,6 +359,8 @@ internal static object SafeConvert(object source, Type targetType)
357359
{
358360
if (ReferenceEquals(source, null)) return null;
359361
if (targetType.IsInstanceOfType(source)) return source;
362+
363+
if (source is string && targetType == typeof(Guid)) return TypeDescriptor.GetConverter(typeof(Guid)).ConvertFromInvariantString(source.ToString());
360364
return Convert.ChangeType(source, targetType);
361365
}
362366

0 commit comments

Comments
 (0)