diff --git a/src/Z.Core/System.Object/Convert/Object.ToOrDefault.cs b/src/Z.Core/System.Object/Convert/Object.ToOrDefault.cs index f585bf06..255bcf7e 100644 --- a/src/Z.Core/System.Object/Convert/Object.ToOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/Object.ToOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.ComponentModel; diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToBooleanOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToBooleanOrDefault.cs index 211d1a06..aacc87ec 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToBooleanOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToBooleanOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static bool ToBooleanOrDefault(this object @this, bool defaultValue) { try { - return Convert.ToBoolean(@this); + return Convert.ToBoolean(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static bool ToBooleanOrDefault(this object @this, Func defaultValue { try { - return Convert.ToBoolean(@this); + return Convert.ToBoolean(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToByteOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToByteOrDefault.cs index 9dc2e2c3..99efb6bd 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToByteOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToByteOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static byte ToByteOrDefault(this object @this, byte defaultValue) { try { - return Convert.ToByte(@this); + return Convert.ToByte(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static byte ToByteOrDefault(this object @this, Func defaultValueFac { try { - return Convert.ToByte(@this); + return Convert.ToByte(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToCharOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToCharOrDefault.cs index cfbfdf19..5b0be046 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToCharOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToCharOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static char ToCharOrDefault(this object @this, char defaultValue) { try { - return Convert.ToChar(@this); + return Convert.ToChar(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static char ToCharOrDefault(this object @this, Func defaultValueFac { try { - return Convert.ToChar(@this); + return Convert.ToChar(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDateTimeOffSetOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDateTimeOffSetOrDefault.cs index c0dfd821..1a10eb86 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDateTimeOffSetOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDateTimeOffSetOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static DateTimeOffset ToDateTimeOffSetOrDefault(this object @this, DateTi { try { - return new DateTimeOffset(Convert.ToDateTime(@this), TimeSpan.Zero); + return new DateTimeOffset(Convert.ToDateTime(@this ?? ""), TimeSpan.Zero); } catch (Exception) { @@ -53,7 +53,7 @@ public static DateTimeOffset ToDateTimeOffSetOrDefault(this object @this, Func def { try { - return Convert.ToDateTime(@this); + return Convert.ToDateTime(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDecimalOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDecimalOrDefault.cs index c5e7e014..8d6d0fd1 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDecimalOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDecimalOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static decimal ToDecimalOrDefault(this object @this, decimal defaultValue { try { - return Convert.ToDecimal(@this); + return Convert.ToDecimal(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static decimal ToDecimalOrDefault(this object @this, Func defaul { try { - return Convert.ToDecimal(@this); + return Convert.ToDecimal(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDoubleOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDoubleOrDefault.cs index 543eb83c..272d3696 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDoubleOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToDoubleOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static double ToDoubleOrDefault(this object @this, double defaultValue) { try { - return Convert.ToDouble(@this); + return Convert.ToDouble(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static double ToDoubleOrDefault(this object @this, Func defaultVa { try { - return Convert.ToDouble(@this); + return Convert.ToDouble(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToFloatOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToFloatOrDefault.cs index 2a0c7656..1edf943d 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToFloatOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToFloatOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static float ToFloatOrDefault(this object @this, float defaultValue) { try { - return Convert.ToSingle(@this); + return Convert.ToSingle(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static float ToFloatOrDefault(this object @this, Func defaultValue { try { - return Convert.ToSingle(@this); + return Convert.ToSingle(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToGuidOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToGuidOrDefault.cs index 763ac9b0..ba603b76 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToGuidOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToGuidOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt16OrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt16OrDefault.cs index 10d3ca44..14bdae57 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt16OrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt16OrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static short ToInt16OrDefault(this object @this, short defaultValue) { try { - return Convert.ToInt16(@this); + return Convert.ToInt16(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static short ToInt16OrDefault(this object @this, Func defaultValue { try { - return Convert.ToInt16(@this); + return Convert.ToInt16(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt32OrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt32OrDefault.cs index 62519158..e288cf07 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt32OrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt32OrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static int ToInt32OrDefault(this object @this, int defaultValue) { try { - return Convert.ToInt32(@this); + return Convert.ToInt32(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static int ToInt32OrDefault(this object @this, Func defaultValueFact { try { - return Convert.ToInt32(@this); + return Convert.ToInt32(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt64OrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt64OrDefault.cs index 0b4b520d..43de5235 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt64OrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToInt64OrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static long ToInt64OrDefault(this object @this, long defaultValue) { try { - return Convert.ToInt64(@this); + return Convert.ToInt64(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static long ToInt64OrDefault(this object @this, Func defaultValueFa { try { - return Convert.ToInt64(@this); + return Convert.ToInt64(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToLongOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToLongOrDefault.cs index 7e3f41cc..62f59a28 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToLongOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToLongOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static long ToLongOrDefault(this object @this, long defaultValue) { try { - return Convert.ToInt64(@this); + return Convert.ToInt64(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static long ToLongOrDefault(this object @this, Func defaultValueFac { try { - return Convert.ToInt64(@this); + return Convert.ToInt64(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToNullableBooleanOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToNullableBooleanOrDefault.cs index 20faf0c0..c0479151 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToNullableBooleanOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToNullableBooleanOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToSByteOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToSByteOrDefault.cs index e696e323..15a4fe44 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToSByteOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToSByteOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static sbyte ToSByteOrDefault(this object @this, sbyte defaultValue) { try { - return Convert.ToSByte(@this); + return Convert.ToSByte(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static sbyte ToSByteOrDefault(this object @this, Func defaultValue { try { - return Convert.ToSByte(@this); + return Convert.ToSByte(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToShortOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToShortOrDefault.cs index c3751f30..34ea1bd2 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToShortOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToShortOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static short ToShortOrDefault(this object @this, short defaultValue) { try { - return Convert.ToInt16(@this); + return Convert.ToInt16(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static short ToShortOrDefault(this object @this, Func defaultValue { try { - return Convert.ToInt16(@this); + return Convert.ToInt16(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToSingleOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToSingleOrDefault.cs index f6ae7312..d734bce4 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToSingleOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToSingleOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static float ToSingleOrDefault(this object @this, float defaultValue) { try { - return Convert.ToSingle(@this); + return Convert.ToSingle(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static float ToSingleOrDefault(this object @this, Func defaultValu { try { - return Convert.ToSingle(@this); + return Convert.ToSingle(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToStringOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToStringOrDefault.cs index ec1df75a..edbf5578 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToStringOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToStringOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt16OrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt16OrDefault.cs index ddbf6c36..6482c9fd 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt16OrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt16OrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static ushort ToUInt16OrDefault(this object @this, ushort defaultValue) { try { - return Convert.ToUInt16(@this); + return Convert.ToUInt16(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static ushort ToUInt16OrDefault(this object @this, Func defaultVa { try { - return Convert.ToUInt16(@this); + return Convert.ToUInt16(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt32OrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt32OrDefault.cs index e640c2a0..0bebb6ca 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt32OrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt32OrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static uint ToUInt32OrDefault(this object @this, uint defaultValue) { try { - return Convert.ToUInt32(@this); + return Convert.ToUInt32(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static uint ToUInt32OrDefault(this object @this, Func defaultValueF { try { - return Convert.ToUInt32(@this); + return Convert.ToUInt32(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt64OrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt64OrDefault.cs index 8ff5b0c7..a6ea3199 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt64OrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUInt64OrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static ulong ToUInt64OrDefault(this object @this, ulong defaultValue) { try { - return Convert.ToUInt64(@this); + return Convert.ToUInt64(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static ulong ToUInt64OrDefault(this object @this, Func defaultValu { try { - return Convert.ToUInt64(@this); + return Convert.ToUInt64(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToULongOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToULongOrDefault.cs index 5b6c55a0..0a226834 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToULongOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToULongOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static ulong ToULongOrDefault(this object @this, ulong defaultValue) { try { - return Convert.ToUInt64(@this); + return Convert.ToUInt64(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static ulong ToULongOrDefault(this object @this, Func defaultValue { try { - return Convert.ToUInt64(@this); + return Convert.ToUInt64(@this ?? ""); } catch (Exception) { diff --git a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUShortOrDefault.cs b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUShortOrDefault.cs index b17bcab6..5178942d 100644 --- a/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUShortOrDefault.cs +++ b/src/Z.Core/System.Object/Convert/ToValueType/Object.ToUShortOrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; public static partial class Extensions @@ -35,7 +35,7 @@ public static ushort ToUShortOrDefault(this object @this, ushort defaultValue) { try { - return Convert.ToUInt16(@this); + return Convert.ToUInt16(@this ?? ""); } catch (Exception) { @@ -53,7 +53,7 @@ public static ushort ToUShortOrDefault(this object @this, Func defaultVa { try { - return Convert.ToUInt16(@this); + return Convert.ToUInt16(@this ?? ""); } catch (Exception) { diff --git a/test/Z.Core.Test/System.Object/Object.ToInt32OrDefault.cs b/test/Z.Core.Test/System.Object/Object.ToInt32OrDefault.cs index 592a9cf4..3d58a841 100644 --- a/test/Z.Core.Test/System.Object/Object.ToInt32OrDefault.cs +++ b/test/Z.Core.Test/System.Object/Object.ToInt32OrDefault.cs @@ -3,7 +3,7 @@ // Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues // License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. +// Copyright ?ZZZ Projects Inc. 2014 - 2016. All rights reserved. using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Z.Core.Test @@ -17,6 +17,8 @@ public void ToInt32OrDefault() // Type string @thisValid = "32"; string @thisInvalid = "FizzBuzz"; + string @thisNull = null; + string @thisEmpty = ""; // Exemples int result1 = @thisValid.ToInt32OrDefault(); // return 32; @@ -24,6 +26,9 @@ public void ToInt32OrDefault() int result3 = @thisInvalid.ToInt32OrDefault(-1); // return -1; int result4 = @thisInvalid.ToInt32OrDefault(() => -2); // return -2; + int result5 = @thisNull.ToInt32OrDefault(-1); + int result6 = thisEmpty.ToInt32OrDefault(-1); + // Unit Test Assert.AreEqual(32, result1); Assert.AreEqual(0, result2);