using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MyCode.Project.Infrastructure.Common; namespace MyCode.Project.Infrastructure.Extensions { public static partial class Extensions { #region ToBool(转换为bool) /// /// 转换为bool /// /// 数据 /// public static bool ToBool(this string obj) { return Conv.ToBool(obj); } /// /// 转换为可空bool /// /// 数据 /// public static bool? ToBoolOrNull(this string obj) { return Conv.ToBoolOrNull(obj); } #endregion #region ToInt(转换为int) /// /// 转换为int /// /// 数据 /// public static int ToInt(this string obj) { return Conv.ToInt(obj); } /// /// 转换为可空int /// /// 数据 /// public static int? ToIntOrNull(this string obj) { return Conv.ToIntOrNull(obj); } #endregion #region ToLong(转换为long) /// /// 转换为long /// /// 数据 /// public static long ToLong(this string obj) { return Conv.ToLong(obj); } /// /// 转换为可空long /// /// 数据 /// public static long? ToLongOrNull(this string obj) { return Conv.ToLongOrNull(obj); } #endregion #region ToDouble(转换为double) /// /// 转换为double /// /// 数据 /// public static double ToDouble(this string obj) { return Conv.ToDouble(obj); } /// /// 转换为可空double /// /// 数据 /// public static double? ToDoubleOrNull(this string obj) { return Conv.ToDoubleOrNull(obj); } #endregion #region ToDecimal(转换为decimal) /// /// 转换为decimal /// /// 数据 /// public static decimal ToDecimal(this string obj) { return Conv.ToDecimal(obj); } /// /// 转换为可空decimal /// /// 数据 /// public static decimal? ToDecimalOrNull(this string obj) { return Conv.ToDecimalOrNull(obj); } #endregion #region ToDate(转换为日期) /// /// 转换为日期 /// /// 数据 /// public static DateTime ToDate(this string obj) { return Conv.ToDate(obj); } /// /// 转换为可空日期 /// /// 数据 /// public static DateTime? ToDateOrNull(this string obj) { return Conv.ToDateOrNull(obj); } #endregion #region ToGuid(转换为Guid) /// /// 转化为Guid /// /// 数据 /// public static Guid ToGuid(this string obj) { return Conv.ToGuid(obj); } /// /// 转换为可空Guid /// /// 数据 /// public static Guid? ToGuidOrNull(this string obj) { return Conv.ToGuidOrNull(obj); } /// /// 转换为Guid集合 /// /// 数据,范例:"83B0233C-A24F-49FD-8083-1337209EBC9A,EAB523C6-2FE7-47BE-89D5-C6D440C3033A" /// public static List ToGuidList(this string obj) { return Conv.ToGuidList(obj); } /// /// 转换为Guid集合 /// /// 字符串集合 /// public static List ToGuidList(this IList obj) { if (obj == null) { return new List(); } return obj.Select(t => t.ToGuid()).ToList(); } #endregion } }