Files
GateDge2023_ljy/01.扩展/Extensions/ObjectExtension.cs

25 lines
531 B
C#
Raw Normal View History

2024-03-04 16:50:20 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ExtensionMethods
{
public static class ObjectExtension
{
public static string ToSafeTurnString(this object obj)
{
if (obj == null)
return string.Empty;
return obj.ToString();
}
2024-05-15 13:56:09 +08:00
public static bool ToBool(this object obj)
{
bool.TryParse(obj.ToSafeTurnString(), out bool resultVal);
return resultVal;
}
2024-03-04 16:50:20 +08:00
}
}