object.ToString(string)

Here are the examples of the csharp api object.ToString(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

23 Examples 7

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static short ToShort(this object o, short t = default(short))
        {
            short info;
            if (!short.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static ulong ToULong(this object o, ulong t = default(ulong))
        {
            ulong info;
            if (!ulong.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static string ToFileName(this string s)
        {
            return Regex.Replace(s.ToString(string.Empty), @"[\\/:*?<>|]", "_").Replace("\t", " ").Replace("\r\n", " ").Replace("\"", " ");
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static decimal ToDecimal(this object o, decimal t = default(decimal))
        {
            decimal info;
            if (!decimal.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static long ToLong(this object o, long t = default(long))
        {
            long info;
            if (!long.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static DateTime ToDateTime(this object o, DateTime t = default(DateTime))
        {
            if (t == default(DateTime))
            {
                t = new DateTime(1753, 1, 1);
            }
            DateTime info;
            if (!DateTime.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static Guid? GetGuid(this object o)
        {
            Guid info;
            if (!Guid.TryParse(GuidRegex.Match(o.ToString(string.Empty)).Groups["info"].Value, out info))
            {
                return null;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static char ToChar(this object o, char t = default(char))
        {
            if (!char.TryParse(o.ToString(string.Empty), out char info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static byte ToByte(this object o, byte t = default(byte))
        {
            if (!byte.TryParse(o.ToString(string.Empty), out byte info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static int ToInt(this object o, int t = default(int))
        {
            if (!int.TryParse(o.ToString(string.Empty), out int info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static double ToDouble(this object o, double t = default(double))
        {
            double info;
            if (!double.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static float ToFloat(this object o, float t = default(float))
        {
            if (!float.TryParse(o.ToString(string.Empty), out float info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static bool ToBool(this object o, bool t = default(bool))
        {
            bool info;
            if (!bool.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static sbyte ToSbyte(this object o, sbyte t = default(sbyte))
        {
            sbyte info;
            if (!sbyte.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static ushort ToUShort(this object o, ushort t = default(ushort))
        {
            ushort info;
            if (!ushort.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static TimeSpan? GetTimeSpan(this object o)
        {
            TimeSpan info;
            if (!TimeSpan.TryParse(TimeSpanRegex.Match(o.ToString(string.Empty)).Groups["info"].Value, out info))
            {
                return null;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static DateTime? GetSqlDateTime(this object o, DateTime t = default(DateTime))
        {
            DateTime info;
            if (!DateTime.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            if (info < new DateTime(1753, 1, 1) || info > new DateTime(9999, 12, 31))
            {
                return null;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static T ToEnum<T>(this object o, T t = default(T))
            where T : struct
        {
            if (!System.Enum.TryParse(o.ToString(string.Empty), out T info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static TimeSpan ToTimeSpan(this object o, TimeSpan t = default(TimeSpan))
        {
            if (t == default(TimeSpan))
            {
                t = new TimeSpan(0, 0, 0);
            }
            TimeSpan info;
            if (!TimeSpan.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static Guid ToGuid(this object o, Guid t = default(Guid))
        {
            Guid info;
            if (!Guid.TryParse(o.ToString(string.Empty), out info))
            {
                info = t;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static decimal? GetDecimal(this object o)
        {
            decimal info;
            if (!decimal.TryParse(DecimalRegex.Match(o.ToString(string.Empty)).Groups["info"].Value, out info))
            {
                return null;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static DateTime? GetDateTime1(this object o)
        {
            DateTime info;
            if (!DateTime.TryParse(DateTimeRegex.Match(o.ToString(string.Empty)).Groups["info"].Value.Replace("年", "-").Replace("月", "-").Replace("/", "-").Replace("日", ""), out info))
            {
                return null;
            }
            return info;
        }

19 Source : ObjectExtension.cs
with MIT License
from cq-panda

public static decimal? GetPositiveNumber(this object o)
        {
            decimal info;
            if (!decimal.TryParse(DecimalRegex.Match(o.ToString(string.Empty)).Groups["info"].Value, out info))
            {
                return null;
            }
            return Math.Abs(info);
        }