ExcelUnity/Core/CommonHelper.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

namespace ExcelUnity.Core
{
    internal static class CommonHelper
    {
        /// <summary>
        /// 属性是Nullable泛型
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        public static bool IsNullable(this PropertyInfo property)
        {
            return property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>);
        }

        /// <summary>
        /// 值类型转换
        /// </summary>
        /// <param name="value">当前值</param>
        /// <param name="targetType">目标类型</param>
        /// <returns></returns>
        public static object ConvertValueType(string value, Type targetType)
        {
            object ret = targetType.Name switch
            {
                "Guid" => Guid.Parse(value),
                _ => Convert.ChangeType(value, targetType),
            };
            return ret;
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。