sunpengfei
2025-08-12 fb118d8c232bd9a0b28a94a0c23488b7c95817ed
FlexJobApi.Core/Utils/StringUtils/StringUtils.cs
@@ -1,4 +1,6 @@
using System;
using Furion.FriendlyException;
using Mapster.Utils;
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Diagnostics.CodeAnalysis;
@@ -33,9 +35,10 @@
            return !str.IsNull();
        }
        public static Guid? ToGuid(this string str)
        public static Guid? ToGuid(this string str, string requiredMessage = null)
        {
            if (str.IsNotNull() && Guid.TryParse(str, out var guid) && guid != Guid.Empty) return guid;
            if (requiredMessage.IsNotNull()) throw Oops.Oh(EnumErrorCodeType.s400, requiredMessage);
            return null;
        }
@@ -45,6 +48,14 @@
            return null;
        }
        public static T? ToEnum<T>(this string str, string requiredMessage = null)
             where T : struct
        {
            if (str.IsNotNull() && Enum.TryParse<T>(str, out var @enum)) return @enum;
            if (requiredMessage.IsNotNull()) throw Oops.Oh(EnumErrorCodeType.s400, requiredMessage);
            return null;
        }
        /// <summary>
        /// 获取复数英文名
        /// </summary>