コード例 #1
0
ファイル: TypeHelper.cs プロジェクト: jianghang123/TestCore
        /// <summary>
        /// 获取主键,自增长,不允许编辑的成员名称
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Tuple <List <string>, List <string>, List <string> > GetKeyNames(this Type type)
        {
            var pkFields   = new List <string>();
            var idetFields = new List <string>();
            var exFields   = new List <string>();

            var metaPros = GetFlogProperties(type);

            if (metaPros != null && metaPros.Any())
            {
                FieldInfoAttribute attr = null;
                foreach (var p in metaPros)
                {
                    attr = p.GetCustomAttribute <FieldInfoAttribute>();

                    if (attr != null)
                    {
                        if (attr.IsPK)
                        {
                            pkFields.Add(p.Name);
                        }
                        if (attr.IsIdEntity)
                        {
                            idetFields.Add(p.Name);
                        }
                        if (attr.IsAllowEdit == false)
                        {
                            exFields.Add(p.Name);
                        }
                    }
                }
            }
            return(Tuple.Create(pkFields, idetFields, exFields));
        }
コード例 #2
0
ファイル: ExcelReport.cs プロジェクト: r00xus/AzureDevOps
        protected Dictionary <string, FieldInfoAttribute> CreateFieldInfo(Type type)
        {
            var result = new Dictionary <string, FieldInfoAttribute>();

            var properties = type.GetProperties();

            foreach (var propery in properties)
            {
                var attr = type.GetAttributeFromType <FieldInfoAttribute>(propery.Name);

                if (attr == null)
                {
                    attr = new FieldInfoAttribute();
                }

                if (attr.NoDisplay)
                {
                    continue;
                }

                if (attr.Title == null)
                {
                    attr.Title = propery.Name;
                }

                result[propery.Name] = attr;
            }

            return(result);
        }
コード例 #3
0
ファイル: TypeHelper.cs プロジェクト: jianghang123/TestCore
        /// <summary>
        /// 获取单一主键名称
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string  GetPkName(this Type type)
        {
            var metaType            = type.GetTypeInfo().GetCustomAttribute <ModelMetadataTypeAttribute>();
            FieldInfoAttribute temp = null;

            PropertyInfo[] pros = null;
            if (metaType != null)
            {
                pros = metaType.MetadataType.GetProperties().Where(p => (temp = p.GetCustomAttribute <FieldInfoAttribute>()) != null && temp.IsPK)
                       .ToArray();
                if (pros.Any())
                {
                    return(pros.Select(c => c.Name).FirstOrDefault());
                }
            }
            pros = type.GetProperties().Where(p => (temp = p.GetCustomAttribute <FieldInfoAttribute>()) != null && temp.IsPK).ToArray();
            if (pros.Any())
            {
                return(pros.Select(c => c.Name).FirstOrDefault());
            }
            return(string.Empty);
        }