zoukankan      html  css  js  c++  java
  • 对象是否为空的扩展方法

    public static bool IsNull<T>(this T thisValue)
            {
                PropertyInfo[] rs = thisValue.GetType().GetProperties();
                var res = true;
                foreach (PropertyInfo prop in rs)
                {
                    PropertyInfo info = typeof(T).GetProperty(prop.Name);
    
                    var value = info.GetValue(thisValue);
    
                    var targetType = info.GetMethod.ReturnType;
                    var defaultValue = targetType.IsValueType ? Activator.CreateInstance(targetType) : null;
    
                    if (!Equals(value, defaultValue))
                    {
                        res = false;
                        break;
                    }
    
                }
                return res;
            }
    
    
            public static bool NotNull<T>(this T thisValue)
            {
                PropertyInfo[] rs = thisValue.GetType().GetProperties();
                var res = false;
                foreach (PropertyInfo prop in rs)
                {
                    PropertyInfo info = typeof(T).GetProperty(prop.Name);
    
                    var value = info.GetValue(thisValue);
    
                    var targetType = info.GetMethod.ReturnType;
                    var defaultValue = targetType.IsValueType ? Activator.CreateInstance(targetType) : null;
    
                    if (!Equals(value, defaultValue))
                    {
                        res = true;
                        break;
                    }
    
                }
                return res;
            }
  • 相关阅读:
    Dubbo2.0
    Dubbo--RPC框架
    ActiveMQ消息队列
    quartz开源任务调度框架
    webService
    crud最常用
    springBoot第三天
    springmvc--依赖
    springBoot第二天
    pom.xml和settings.xml的下载优先级
  • 原文地址:https://www.cnblogs.com/ImaY/p/13581236.html
Copyright © 2011-2022 走看看