Exemplo n.º 1
0
        public static List <DbDescription> GetDescription()
        {
            var d = new List <DbDescription>();

            List <FileListModel> filelist = new List <FileListModel>();

            getDirectory(filelist, c);

            var e = Assembly.Load(b);
            var f = e?.GetTypes();
            var g = f?
                    .Where(t => t.IsClass &&
                           !t.IsGenericType &&
                           !t.IsAbstract
                           //&& t.GetInterfaces().Any(m => m.GetGenericTypeDefinition() == typeof(IBaseModel<>))
                           ).ToList();

            foreach (var h in g)
            {
                var i = new DbDescription();

                System.Type          tp          = e.GetType(h.FullName);
                DescriptionAttribute attributeTB = Attribute.GetCustomAttribute(tp, typeof(DescriptionAttribute)) as DescriptionAttribute;
                var z = "";
                if (attributeTB != null)
                {
                    z = attributeTB.Description;
                }
                var n = new List <DbDescription>();

                //3.2.3 获取实体类所有的公共属性
                List <PropertyInfo> propertyInfos = tp.GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();
                //propertyInfos.ForEach(p =>
                //{
                //    //Console.WriteLine(p.Name);
                //    DescriptionAttribute attribute = Attribute.GetCustomAttribute(p, typeof(DescriptionAttribute)) as DescriptionAttribute;

                //    if (attribute != null)
                //    {
                //        var dect = attribute.Description;
                //        n.Add(new DbDescription { Name = p.Name, Description = dect });
                //    }
                //});


                if (filelist.Count(xx => xx.FileName == h.Name + ".cs") == 0)
                {
                    continue;
                }

                #region MyRegion
                var j = filelist.FirstOrDefault(xx => xx.FileName == h.Name + ".cs").FullName;

                //var j = c + "\\" + h.Name + ".cs";
                var k = File.ReadAllText(j);
                k = k.Substring(k.IndexOf("{") + 1, k.LastIndexOf("}") - k.IndexOf("{") - 1).Replace("\n", "");

                var      l     = k.Substring(k.IndexOf(" {") + 2, k.LastIndexOf(" }") - k.IndexOf(" {") - 1).Replace("\n", "");
                string[] slipt = { "}\r" };
                var      m     = l.Split(slipt, StringSplitOptions.None).ToList();

                //var n = new List<DbDescription>();
                foreach (var o in m)
                {
                    var p = o.Replace("///", "");

                    var q = p.IndexOf("<summary>");
                    var r = p.LastIndexOf("</summary>");

                    var s = p.IndexOf("public");
                    var t = p.IndexOf("{");

                    var u = (q > 0 && r > 0) ? p.Substring(q + 9, r - q - 10).Replace("\r", "").Replace(" ", "") : "";
                    var v = (s > 0 && t > 0) ? p.Substring(s, t - s).Split(' ')[2] : "";

                    n.Add(new DbDescription()
                    {
                        Description = u,
                        Name        = v
                    });
                }

                var w = k.Substring(0, k.IndexOf("{\r") - 1);
                w = w.Replace("///", "");

                var x = w.IndexOf("<summary>");
                var y = w.LastIndexOf("</summary>");
                z = (x > 0 && y > 0) ? w.Substring(x + 9, y - x - 10).Replace("\r", "").Replace(" ", "") : "";
                #endregion


                d.Add(new DbDescription()
                {
                    Name        = h.Name,
                    Description = z,
                    Column      = n
                });
            }
            return(d);
        }
Exemplo n.º 2
0
        public static List <DbDescription> GetDescription()
        {
            var d = new List <DbDescription>();

            var e = Assembly.Load(b);
            var f = e?.GetTypes();
            var g = f?
                    .Where(t => t.IsClass &&
                           !t.IsGenericType &&
                           !t.IsAbstract
                           //&& t.GetInterfaces().Any(m => m.GetGenericTypeDefinition() == typeof(IBaseModel<>))
                           ).ToList();

            foreach (var h in g)
            {
                var i = new DbDescription();

                System.Type          t           = e.GetType(h.FullName);
                DescriptionAttribute attributeTB = Attribute.GetCustomAttribute(t, typeof(DescriptionAttribute)) as DescriptionAttribute;
                var z = "";
                if (attributeTB != null)
                {
                    z = attributeTB.Description;
                }
                var n = new List <DbDescription>();

                //3.2.3 获取实体类所有的公共属性
                List <PropertyInfo> propertyInfos = t.GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();
                propertyInfos.ForEach(p =>
                {
                    //Console.WriteLine(p.Name);
                    DescriptionAttribute attribute = Attribute.GetCustomAttribute(p, typeof(DescriptionAttribute)) as DescriptionAttribute;

                    DatabaseGeneratedAttribute dbattribute = Attribute.GetCustomAttribute(p, typeof(DatabaseGeneratedAttribute)) as DatabaseGeneratedAttribute;


                    if (attribute != null || (dbattribute != null && dbattribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity))
                    {
                        var dect   = attribute != null ? attribute.Description : "";
                        int iszzpk = 0;
                        if (dbattribute != null && dbattribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity)
                        {
                            iszzpk = 1;
                        }
                        n.Add(new DbDescription {
                            Name = p.Name, Description = dect, IsZZPK = iszzpk
                        });
                    }



                    #region MyRegion
                    //var j = c + "\\" + h.Name + ".cs";
                    //var k = File.ReadAllText(j);
                    //k = k.Substring(k.IndexOf("{") + 1, k.LastIndexOf("}") - k.IndexOf("{") - 1).Replace("\n", "");

                    //var l = k.Substring(k.IndexOf(" {") + 2, k.LastIndexOf(" }") - k.IndexOf(" {") - 1).Replace("\n", "");
                    //string[] slipt = { "}\r" };
                    //var m = l.Split(slipt, StringSplitOptions.None).ToList();

                    //var n = new List<DbDescription>();
                    //foreach (var o in m)
                    //{
                    //    var p = o.Replace("///", "");

                    //    var q = p.IndexOf("<summary>");
                    //    var r = p.LastIndexOf("</summary>");

                    //    var s = p.IndexOf("public");
                    //    var t = p.IndexOf("{");

                    //    var u = (q > 0 && r > 0) ? p.Substring(q + 9, r - q - 10).Replace("\r", "").Replace(" ", "") : "";
                    //    var v = (s > 0 && t > 0) ? p.Substring(s, t - s).Split(' ')[2] : "";

                    //    n.Add(new DbDescription()
                    //    {
                    //        Description = u,
                    //        Name = v
                    //    });
                    //}

                    //var w = k.Substring(0, k.IndexOf("{\r") - 1);
                    //w = w.Replace("///", "");

                    //var x = w.IndexOf("<summary>");
                    //var y = w.LastIndexOf("</summary>");
                    //var z = (x > 0 && y > 0) ? w.Substring(x + 9, y - x - 10).Replace("\r", "").Replace(" ", "") : "";
                    #endregion
                });

                d.Add(new DbDescription()
                {
                    Name        = h.Name,
                    Description = z,
                    Column      = n
                });
            }
            return(d);
        }