Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Z.Core/System.Object/Convert/Object.ToOrDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static bool ToBooleanOrDefault(this object @this, bool defaultValue)
{
try
{
return Convert.ToBoolean(@this);
return Convert.ToBoolean(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static bool ToBooleanOrDefault(this object @this, Func<bool> defaultValue
{
try
{
return Convert.ToBoolean(@this);
return Convert.ToBoolean(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static byte ToByteOrDefault(this object @this, byte defaultValue)
{
try
{
return Convert.ToByte(@this);
return Convert.ToByte(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static byte ToByteOrDefault(this object @this, Func<byte> defaultValueFac
{
try
{
return Convert.ToByte(@this);
return Convert.ToByte(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static char ToCharOrDefault(this object @this, char defaultValue)
{
try
{
return Convert.ToChar(@this);
return Convert.ToChar(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static char ToCharOrDefault(this object @this, Func<char> defaultValueFac
{
try
{
return Convert.ToChar(@this);
return Convert.ToChar(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -53,7 +53,7 @@ public static DateTimeOffset ToDateTimeOffSetOrDefault(this object @this, Func<D
{
try
{
return new DateTimeOffset(Convert.ToDateTime(@this), TimeSpan.Zero);
return new DateTimeOffset(Convert.ToDateTime(@this ?? ""), TimeSpan.Zero);
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static DateTime ToDateTimeOrDefault(this object @this, DateTime defaultVa
{
try
{
return Convert.ToDateTime(@this);
return Convert.ToDateTime(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static DateTime ToDateTimeOrDefault(this object @this, Func<DateTime> def
{
try
{
return Convert.ToDateTime(@this);
return Convert.ToDateTime(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static decimal ToDecimalOrDefault(this object @this, decimal defaultValue
{
try
{
return Convert.ToDecimal(@this);
return Convert.ToDecimal(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static decimal ToDecimalOrDefault(this object @this, Func<decimal> defaul
{
try
{
return Convert.ToDecimal(@this);
return Convert.ToDecimal(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static double ToDoubleOrDefault(this object @this, double defaultValue)
{
try
{
return Convert.ToDouble(@this);
return Convert.ToDouble(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static double ToDoubleOrDefault(this object @this, Func<double> defaultVa
{
try
{
return Convert.ToDouble(@this);
return Convert.ToDouble(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static float ToFloatOrDefault(this object @this, float defaultValue)
{
try
{
return Convert.ToSingle(@this);
return Convert.ToSingle(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static float ToFloatOrDefault(this object @this, Func<float> defaultValue
{
try
{
return Convert.ToSingle(@this);
return Convert.ToSingle(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static short ToInt16OrDefault(this object @this, short defaultValue)
{
try
{
return Convert.ToInt16(@this);
return Convert.ToInt16(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static short ToInt16OrDefault(this object @this, Func<short> defaultValue
{
try
{
return Convert.ToInt16(@this);
return Convert.ToInt16(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static int ToInt32OrDefault(this object @this, int defaultValue)
{
try
{
return Convert.ToInt32(@this);
return Convert.ToInt32(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static int ToInt32OrDefault(this object @this, Func<int> defaultValueFact
{
try
{
return Convert.ToInt32(@this);
return Convert.ToInt32(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static long ToInt64OrDefault(this object @this, long defaultValue)
{
try
{
return Convert.ToInt64(@this);
return Convert.ToInt64(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static long ToInt64OrDefault(this object @this, Func<long> defaultValueFa
{
try
{
return Convert.ToInt64(@this);
return Convert.ToInt64(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static long ToLongOrDefault(this object @this, long defaultValue)
{
try
{
return Convert.ToInt64(@this);
return Convert.ToInt64(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static long ToLongOrDefault(this object @this, Func<long> defaultValueFac
{
try
{
return Convert.ToInt64(@this);
return Convert.ToInt64(@this ?? "");
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ public static sbyte ToSByteOrDefault(this object @this, sbyte defaultValue)
{
try
{
return Convert.ToSByte(@this);
return Convert.ToSByte(@this ?? "");
}
catch (Exception)
{
Expand All @@ -53,7 +53,7 @@ public static sbyte ToSByteOrDefault(this object @this, Func<sbyte> defaultValue
{
try
{
return Convert.ToSByte(@this);
return Convert.ToSByte(@this ?? "");
}
catch (Exception)
{
Expand Down
Loading