-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to ignore null value for specified properties.
Fix exception when null assigned to a nullable value type.
- Loading branch information
Showing
8 changed files
with
130 additions
and
21 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Reflection; | ||
|
||
namespace SimplePatch | ||
{ | ||
internal class DeltaInfo | ||
{ | ||
public bool IgnoreNullValue { get; set; } = false; | ||
public PropertyInfo PropertyInfo { get; set; } | ||
|
||
public string Name { get => PropertyInfo.Name; } | ||
|
||
public DeltaInfo(PropertyInfo propertyInfo) | ||
{ | ||
PropertyInfo = propertyInfo; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace SimplePatch | ||
{ | ||
internal class TypeHelper | ||
{ | ||
public static IEnumerable<DeltaInfo> GetEntityProperties<TEntity>() | ||
{ | ||
return typeof(TEntity).GetTypeInfo().DeclaredProperties.Where(x => x.GetMethod.IsPublic && x.SetMethod.IsPublic && x.CanRead && x.CanWrite).Select(x => new DeltaInfo(x)); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the type specified by the parameter or type below if <paramref name="type" /> is <see cref="Nullable" />. | ||
/// </summary> | ||
/// <param name="type">The type to be verified.</param> | ||
/// <returns>The type specified by the parameter or type below if <paramref name="type" /> is <see cref="Nullable" />.</returns> | ||
public static Type GetTrueType(Type type) | ||
{ | ||
return Nullable.GetUnderlyingType(type) ?? type; | ||
} | ||
|
||
/// <summary> | ||
/// Indicates whether the specified type accepts null values. | ||
/// </summary> | ||
/// <param name="type">Type to check.</param> | ||
/// <returns>True if the specified type accepts null values, otherwise false.</returns> | ||
public static bool IsNullable(Type type) | ||
{ | ||
if (!type.GetTypeInfo().IsValueType) return true; // ref-type | ||
if (Nullable.GetUnderlyingType(type) != null) return true; // Nullable<T> | ||
return false; | ||
} | ||
} | ||
} |