예제 #1
0
        /// <summary>
        /// Ctor
        /// 枚举属性使用
        /// 性构造ParamModel
        /// </summary>
        /// <param name="fi">FieldInfo</param>
        /// <param name="index"></param>
        private static ParamModel GetParam(FieldInfo fi, int index = 0)
        {
            PTypeModel ptype = GetPType(fi.FieldType);
            int?       value = null;

            if (fi.FieldType.IsEnum)
            {
                try
                {
                    value = Convert.ToInt32(Enum.Parse(fi.FieldType, fi.Name));
                }
                catch
                {   //如转换失败,忽略不做处理
                }
            }

            string fiId = null;

            if (fi.DeclaringType != null)
            {
                fiId = $"F:{fi.DeclaringType.ToString()}.{fi.Name}";
            }

            ParamModel param = new ParamModel()
            {
                Name             = fi.Name,
                Id               = fiId,
                PType            = ptype,
                ParamValue       = value,
                CustomerAttrList = fi.CustomAttributes.Select(a => GetCustomerAttribute(a)).ToList(),
                Position         = index + 1
            };

            return(param);
        }
예제 #2
0
        /// <summary>
        /// Ctor
        /// 类属性使用
        /// 构造ParamModel
        /// </summary>
        /// <param name="pi">参数信息</param>
        /// <param name="index"></param>
        private static ParamModel GetParam(PropertyInfo pi, int index = 0)
        {
            PTypeModel ptype = GetPType(pi.PropertyType);

            string piId = null;

            if (pi.DeclaringType != null)
            {
                string declaringTypeName = pi.DeclaringType.ToString();
                if (declaringTypeName.IndexOf("`") != -1)
                {   //泛型属性Id结构如下:P:Jc.Core.Robj`1.Result
                    declaringTypeName = declaringTypeName.Substring(0, declaringTypeName.IndexOf("`") + 2);
                }
                piId = $"P:{declaringTypeName}.{pi.Name}";
            }

            ParamModel param = new ParamModel()
            {
                Name           = pi.Name,
                Id             = piId,
                PType          = ptype,
                CustomAttrList = pi.CustomAttributes.Select(a => GetCustomAttribute(a)).ToList(),
                Position       = index + 1
            };

            if (pi.CustomAttributes.Count() > 0)
            {
            }
            return(param);
        }
예제 #3
0
        /// <summary>
        /// Ctor
        /// 根据数据类型 自定义参数名
        /// 构造ParamModel
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="index">序号</param>
        private static ParamModel GetParam(Type type, int index = 0)
        {
            PTypeModel ptype = GetPType(type);
            ParamModel param = new ParamModel()
            {
                Name     = $"p{index + 1}",
                PType    = ptype,
                Position = index + 1
            };

            return(param);
        }
예제 #4
0
        /// <summary>
        /// Ctor
        /// Attribute使用
        /// 根据Attribute NamedArgument 命名参数
        /// 构造命名参数ParamModel
        /// </summary>
        /// <param name="namedArgument"></param>
        /// <param name="index">序号</param>
        private static ParamModel GetParam(CustomAttributeNamedArgument namedArgument, int index = 0)
        {
            PTypeModel ptype = GetPType(namedArgument.TypedValue.ArgumentType);
            ParamModel param = new ParamModel()
            {
                Name       = $"p{index + 1}",
                PType      = ptype,
                ParamValue = namedArgument.TypedValue.Value,
                Position   = index
            };

            return(param);
        }
예제 #5
0
        /// <summary>
        /// Ctor
        /// 根据参数信息 输入输出参数
        /// 构造ParamModel
        /// </summary>
        /// <param name="paramInfo">参数信息</param>
        private static ParamModel GetParam(ParameterInfo paramInfo)
        {
            PTypeModel ptype = GetPType(paramInfo.ParameterType);
            ParamModel param = new ParamModel()
            {
                Name         = paramInfo.Name,
                PType        = ptype,
                DefaultValue = paramInfo.DefaultValue?.ToString(),
                Position     = paramInfo.Position + 1
            };

            return(param);
        }
예제 #6
0
        /// <summary>
        /// 获取类对象属性列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private static List <ParamModel> GetClassObjPiList(Type type)
        {
            List <ParamModel> list = new List <ParamModel>();

            if (type.GenericTypeArguments.Length > 0)
            {
                #region 处理GenericTypeArguments>0情况
                if (type.GenericTypeArguments.Length > 1)
                {   //字典类型
                    for (int i = 0; i < type.GenericTypeArguments.Length; i++)
                    {
                        ParamModel param = GetParam(type.GenericTypeArguments[i], i);
                        list.Add(param);
                    }
                    return(list);
                }
                else if (type.GenericTypeArguments.Length == 1)
                {   //单属性时,使用普通方法处理 PageResult<T>等格式
                    List <PropertyInfo> piList = type.GetMembers()
                                                 .Where(a => a.MemberType == MemberTypes.Property)
                                                 .Select(a => a as PropertyInfo).ToList();

                    if (piList?.Count > 0)
                    {
                        for (int i = 0; i < piList.Count; i++)
                        {
                            ParamModel param = GetParam(piList[i], i);
                            list.Add(param);
                        }
                    }
                }
                #endregion
            }
            else
            {
                List <MemberInfo>   memberList = type.GetMembers().ToList();
                List <PropertyInfo> piList     = memberList
                                                 .Where(a => a.MemberType == MemberTypes.Property)
                                                 .Select(a => a as PropertyInfo).ToList();
                if (piList?.Count > 0)
                {
                    for (int i = 0; i < piList.Count; i++)
                    {
                        ParamModel param = GetParam(piList[i], i);
                        list.Add(param);
                    }
                }
            }
            return(list);
        }
예제 #7
0
        /// <summary>
        /// Ctor
        /// 根据参数信息 输入输出参数
        /// 构造ParamModel
        /// </summary>
        /// <param name="paramInfo">参数信息</param>
        private static ParamModel GetParam(ParameterInfo paramInfo)
        {
            PTypeModel ptype = GetPType(paramInfo.ParameterType);
            ParamModel param = new ParamModel()
            {
                Name           = paramInfo.Name,
                PType          = ptype,
                DefaultValue   = paramInfo.DefaultValue?.ToString(),
                CustomAttrList = paramInfo.GetCustomAttributes().Select(a => GetCustomAttribute(a)).ToList(),
                Position       = paramInfo.Position + 1
            };

            return(param);
        }
예제 #8
0
        /// <summary>
        /// 获取枚举字段属性列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private static List <ParamModel> GetEnumPiList(Type type)
        {
            List <ParamModel> list = new List <ParamModel>();

            List <MemberInfo> memberList = type.GetMembers().ToList();
            //去掉枚举value__属性
            List <FieldInfo> fieldList = memberList
                                         .Where(a => a.MemberType == MemberTypes.Field)
                                         .Where(a => a.Name != "value__")
                                         .Select(a => a as FieldInfo).ToList();

            if (fieldList?.Count > 0)
            {
                for (int i = 0; i < fieldList.Count; i++)
                {
                    ParamModel param = GetParam(fieldList[i], i);
                    list.Add(param);
                }
            }
            return(list);
        }