/*internal static PropertyMeta<TEnt, TProp> By(Expression<Func<TEnt, TProp>> expGet)
         * {
         *  var prop = ((MemberExpression) expGet.Body).Member as PropertyInfo;
         *  return new PropertyMeta<TEnt, TProp>(prop)
         *  {
         *      _getter = expGet.Compile()
         *  };
         * }*/

        public PropertyMeta(PropertyInfo prop, PropMetaAttribute attr)
        {
            Name    = prop.Name;
            AttrSet = attr;

            Getter = TypeExtend.GetPropertyGetter <TEnt, TProp>(prop);
            Setter = TypeExtend.GetPropertySetter <TEnt, TProp>(prop);
        }
        /// <summary>
        /// 默认属性值验证
        /// </summary>
        public virtual string Validate(PropMetaAttribute attrSet, TProp propVal)
        {
            if (attrSet.IsRequired && propVal == null)
            {
                return($"未设置{attrSet.CnName}");
            }

            return(null);
        }
        private BasePropMeta <T> Prop(PropertyInfo prop, PropMetaAttribute propSet)
        {
            //用PropertyInfo反射创建Meta
            var meta = Activator.CreateInstance(typeof(PropertyMeta <,>).MakeGenericType(typeof(T), prop.PropertyType), prop, propSet) as BasePropMeta <T>;

            if (meta != null)
            {
                PropMetas.Add(prop.Name, meta);
            }

            return(meta);
        }
        public override string Validate(PropMetaAttribute attrSet, string propVal)
        {
            if (attrSet.IsRequired && propVal.IsNull())
            {
                return($"{attrSet.CnName}不能为空");
            }
            if (attrSet.MaxValue != 0 && propVal?.Length > attrSet.MaxValue)
            {
                return($"{attrSet.CnName}长度不能大于{attrSet.MaxValue}");
            }

            return(null);
        }
        public override string Validate(PropMetaAttribute attrSet, long propVal)
        {
            if (attrSet.IsRequired && propVal <= 0)
            {
                return($"{attrSet.CnName}需大于0");
            }
            if (attrSet.MaxValue != 0 && propVal > attrSet.MaxValue)
            {
                return($"{attrSet.CnName}不能大于{attrSet.MaxValue}");
            }

            return(null);
        }