Skip to content

Commit

Permalink
Cleanup AutoGuid code
Browse files Browse the repository at this point in the history
  • Loading branch information
praeclarum committed May 25, 2017
1 parent c95cca0 commit ed244cd
Showing 1 changed file with 6 additions and 32 deletions.
38 changes: 6 additions & 32 deletions src/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,42 +1334,14 @@ public int Insert (object obj, string extra, Type objType)
if (obj == null || objType == null) {
return 0;
}


var map = GetMapping (objType);

#if USE_NEW_REFLECTION_API
if (map.PK != null && map.PK.IsAutoGuid)
{
// no GetProperty so search our way up the inheritance chain till we find it
PropertyInfo prop;
while (objType != null)
{
var info = objType.GetTypeInfo();
prop = info.GetDeclaredProperty(map.PK.PropertyName);
if (prop != null)
{
if (prop.GetValue(obj, null).Equals(Guid.Empty))
{
prop.SetValue(obj, Guid.NewGuid(), null);
}
break;
}

objType = info.BaseType;
}
}
#else
if (map.PK != null && map.PK.IsAutoGuid) {
var prop = objType.GetProperty(map.PK.PropertyName);
if (prop != null) {
if (prop.GetValue(obj, null).Equals(Guid.Empty)) {
prop.SetValue(obj, Guid.NewGuid(), null);
}
}
if (map.PK != null && map.PK.IsAutoGuid) {
if (map.PK.GetValue (obj).Equals (Guid.Empty)) {
map.PK.SetValue (obj, Guid.NewGuid ());
}
}
#endif


var replacing = string.Compare (extra, "OR REPLACE", StringComparison.OrdinalIgnoreCase) == 0;

Expand Down Expand Up @@ -1963,6 +1935,8 @@ public class Column

public string Name { get; private set; }

public PropertyInfo PropertyInfo => _prop;

public string PropertyName { get { return _prop.Name; } }

public Type ColumnType { get; private set; }
Expand Down

0 comments on commit ed244cd

Please sign in to comment.