diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-02-26 18:25:52 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-02-26 18:25:52 +0200 |
| commit | afb6bbb2123932b3562e1af993eb847d8147bf58 (patch) | |
| tree | a2c458a077551af5be35a729c4e6d976a92b9387 /Software/Visual_Studio/Tango.Core/ExtensionMethods | |
| parent | 61f2658295193dca0fdaa58744925d90bd2f4044 (diff) | |
| download | Tango-afb6bbb2123932b3562e1af993eb847d8147bf58.tar.gz Tango-afb6bbb2123932b3562e1af993eb847d8147bf58.zip | |
Major Changes Regarding RML & SPOOL parameters changes!
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/ExtensionMethods')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs | 12 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs | 15 |
2 files changed, 21 insertions, 6 deletions
diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs index e8ef9addd..cee991507 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs @@ -35,9 +35,9 @@ namespace Tango.Core.ExtensionMethods NoReferenceTypes = 8, /// <summary> - /// Map only primitive values. + /// Map only value types. /// </summary> - PrimitivesOnly, + ValueTypesOnly, } /// <summary> @@ -59,7 +59,7 @@ namespace Tango.Core.ExtensionMethods foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.SetMethod != null)) { - if (!prop.PropertyType.IsGenericType) + if (!prop.PropertyType.IsGenericTypeAndNotNullable()) { prop.SetValue(cloned, prop.GetValue(obj)); } @@ -78,7 +78,7 @@ namespace Tango.Core.ExtensionMethods { foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.SetMethod != null)) { - if (!prop.PropertyType.IsGenericType) + if (!prop.PropertyType.IsGenericTypeAndNotNullable()) { prop.SetValue(destination, prop.GetValue(source)); } @@ -104,7 +104,7 @@ namespace Tango.Core.ExtensionMethods if (!condition(prop)) continue; } - if (!propType.IsPrimitive && flags.HasFlag(MappingFlags.PrimitivesOnly)) + if (!propType.IsValueType && flags.HasFlag(MappingFlags.ValueTypesOnly)) { continue; } @@ -141,7 +141,7 @@ namespace Tango.Core.ExtensionMethods /// <param name="destination">The destination.</param> public static void MapPrimitivesTo(this object source, object destination) { - source.MapPropertiesTo(destination, MappingFlags.PrimitivesOnly); + source.MapPropertiesTo(destination, MappingFlags.ValueTypesOnly); } /// <summary> diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs index c6fd3d811..66978ec19 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/TypeExtensions.cs @@ -122,4 +122,19 @@ public static class TypeExtensions { return type.GetProperties().Where(x => x.GetCustomAttribute<T>() != null); } + + public static bool IsGenericTypeAndNotNullable(this Type type) + { + return type.IsGenericType && Nullable.GetUnderlyingType(type) == null; + } + + public static bool IsNullable(this Type type) + { + return Nullable.GetUnderlyingType(type) != null; + } + + public static bool IsValueTypeOrString(this Type type) + { + return type.IsValueType || type == typeof(String); + } } |
