diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-25 17:52:49 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-25 17:52:49 +0200 |
| commit | 9277bbd2fa070c69b83904f8fe5628fab2b947b8 (patch) | |
| tree | 3099f9ce92f04c28517eb13938e913a1e376b3fe /Software/Visual_Studio/Tango.Core/ExtensionMethods | |
| parent | f779e2b6f0bb1dedc7644c64651b59e31ce62c00 (diff) | |
| download | Tango-9277bbd2fa070c69b83904f8fe5628fab2b947b8.tar.gz Tango-9277bbd2fa070c69b83904f8fe5628fab2b947b8.zip | |
Working on job export import to storage.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/ExtensionMethods')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs | 23 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/ExtensionMethods/StringExtensions.cs | 10 |
2 files changed, 33 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs index 7d0c86e06..cff4e6a3a 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs @@ -74,6 +74,29 @@ public static class ObjectExtensions } /// <summary> + /// Maps the object properties values to the destination object including strings and without assigning null string values from the source. + /// </summary> + /// <param name="source">The source.</param> + /// <param name="destination">The destination.</param> + public static void MapPrimitivesWithStringsNoNullsTo(this object source, object destination) + { + foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive || x.PropertyType == typeof(String))) + { + var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); + + if (desProp != null && (desProp.PropertyType.IsPrimitive || desProp.PropertyType == typeof(String)) && desProp.SetMethod != null) + { + var value = prop.GetValue(source); + + if (desProp.PropertyType != typeof(String) || !String.IsNullOrEmpty(value as String)) + { + desProp.SetValue(destination, value); + } + } + } + } + + /// <summary> /// Maps the object properties values to the destination object. /// </summary> /// <param name="source">The source.</param> diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/StringExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/StringExtensions.cs index 71ed2b03f..f03bcb647 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/StringExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/StringExtensions.cs @@ -223,4 +223,14 @@ public static class StringExtensions "$1 $2" ); } + + public static String ToStringOrEmpty(this String str) + { + return str != null ? str : String.Empty; + } + + public static String ToNullIfEmpty(this String str) + { + return String.IsNullOrEmpty(str) ? null : str; + } } |
