Пример #1
0
        public override IEnumerable <Info.TargetInfo> GetTargetInfoList()
        {
            foreach (var type in GetTypes())
            {
                var exportAttr = type.GetCustomAttribute <ExportAttribute>();

                if (exportAttr == null || !exportAttr.ExportMarks.Contains(ExportMark.ViewModel))
                {
                    continue;
                }

                var areaNameSpace = T4Help.GenerateNameSpace(type, null);
                yield return(new Info.TargetInfo
                {
                    NamespaceName = $"FastFrame.Application.{areaNameSpace}",
                    ImportNames = new[] { "System", "FastFrame.Entity.Enums" }
                    .Concat(type.GetProperties().Select(v => v.PropertyType.Namespace))
                    .Distinct(),
                    Summary = T4Help.GetClassSummary(type, XmlDocDir),
                    Name = $"{type.Name}ViewModel",
                    Path = $"{TargetPath}\\{areaNameSpace}\\{type.Name}\\Dto\\{type.Name}ViewModel.template.cs",
                    CategoryName = "class",
                    PropInfos = GetPropInfos(type),
                    BaseNames = new[] { "IViewModel" },
                    Constructor = new Info.ConstructorInfo
                    {
                        Modifier = "protected",
                    }
                });
            }
        }
Пример #2
0
 public override IEnumerable <TargetInfo> BuildCodeInfo()
 {
     foreach (var type in GetTypes())
     {
         var areaNameSpace = T4Help.GenerateNameSpace(type, null);
         yield return(new TargetInfo()
         {
             NamespaceName = $"FastFrame.Repository.{areaNameSpace}",
             ImportNames = new string[] {
                 $"FastFrame.Entity.{areaNameSpace}",
                 "FastFrame.Database",
                 "FastFrame.Infrastructure.Interface"
             },
             Summary = T4Help.GetClassSummary(type, XmlDocDir) + "[数据访问]",
             Name = $"{type.Name}Repository",
             BaseNames = new string[] { $"BaseRepository<{type.Name}>", $"IRepository<{type.Name}>" },
             Path = $"{TargetPath}",
             CategoryName = "class",
             Constructor = new ConstructorInfo()
             {
                 Parms = new ParameterInfo[] {
                     new ParameterInfo()
                     {
                         TypeName = "DataBase", DefineName = "context"
                     },
                     new ParameterInfo()
                     {
                         TypeName = "ICurrentUserProvider", DefineName = "currentUserProvider"
                     }
                 },
                 Super = new string[] { "context", "currentUserProvider" }
             }
         });
     }
 }
Пример #3
0
 public override IEnumerable <TargetInfo> GetTargetInfoList()
 {
     foreach (var type in GetTypes())
     {
         var areaNameSpace = T4Help.GenerateNameSpace(type, null);
         yield return(new TargetInfo()
         {
             NamespaceName = $"FastFrame.Database.Mapping.{areaNameSpace}",
             ImportNames = new string[] { $"FastFrame.Entity.{areaNameSpace}", "Microsoft.EntityFrameworkCore.Metadata.Builders" },
             Summary = T4Help.GetClassSummary(type, XmlDocDir),
             Name = $"{type.Name}Mapping",
             BaseNames = new string[] { $"BaseEntityMapping<{type.Name}>" },
             Path = $"{TargetPath}\\{areaNameSpace}\\{type.Name}\\{type.Name}Mapping.template.cs",
             CategoryName = "class"
         });
     }
 }
Пример #4
0
        public TargetInfo GetTargetInfo(Type type)
        {
            var areaNameSpace = T4Help.GenerateNameSpace(type, null);

            var attrs = type.GetCustomAttributes <UniqueAttribute>().Select(x => new AttrInfo()
            {
                Name       = "Unique",
                Parameters = x.UniqueNames.Select(y => $"\"{y}\"")
            }).Union(type.GetCustomAttributes <RelatedFieldAttribute>().Select(x => new AttrInfo()
            {
                Name       = "RelatedField",
                Parameters = new[] {
                    $"\"{x.DefaultName}\""
                }.Union(x.OtherNames.Select(y => $"\"{y}\""))
            }));

            return(new Info.TargetInfo()
            {
                NamespaceName = $"FastFrame.Application.{areaNameSpace}",
                ImportNames = new string[] {
                    $"FastFrame.Entity.{areaNameSpace}",
                    "FastFrame.Infrastructure",
                    "System.ComponentModel.DataAnnotations",
                    "FastFrame.Entity.Enums",
                    "FastFrame.Entity.Basis",
                    "FastFrame.Entity",
                    "System.Collections.Generic",
                    "System"
                }
                .Union(type.GetProperties()
                       .Select(x => x.GetCustomAttribute <RelatedToAttribute>())
                       .Where(x => x != null)
                       .SelectMany(x => new[] { x.RelatedType.Namespace,
                                                $"FastFrame.Application.{T4Help.GenerateNameSpace(x.RelatedType,"")}" }))
                .Distinct(),
                Summary = T4Help.GetClassSummary(type, XmlDocDir),
                Name = $"{type.Name}Dto",
                BaseNames = new string[] { $"BaseDto<{type.Name}>" }
                .Concat(typeof(IHaveMultiFile).IsAssignableFrom(type) ? new[] { "IHaveMultiFileDto" } : Array.Empty <string>()),
                Path = $"{TargetPath}\\{areaNameSpace}\\{type.Name}\\Dto\\{type.Name}Dto.template.cs",
                CategoryName = "class",
                PropInfos = GetPropInfos(type),
                AttrInfos = Array.Empty <AttrInfo>() /*attrs*/
            });
        }
Пример #5
0
        public override IEnumerable <BuildTarget> Build(params string[] targetNames)
        {
            var types = this.GetTypes();

            var listVueContent = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "List.vue"));
            var addVueContent  = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Add.vue"));

            foreach (var type in types)
            {
                if (targetNames.Length > 0 && !targetNames.Any(v => type.Name.StartsWith(v)))
                {
                    continue;
                }

                var exportAttr = type.GetCustomAttribute <Entity.ExportAttribute>();

                if (exportAttr == null || !exportAttr.ExportMarks.Contains(Entity.ExportMark.VuePage))
                {
                    continue;
                }

                var areaName = T4Help.GenerateNameSpace(type, null);
                var path     = $"{TargetPath}\\{areaName}\\{type.Name}";

                yield return(new BuildTarget
                {
                    CodeBlock = ReplacePlaceholder(listVueContent, type),
                    TargetPath = Path.Combine(path, "List.vue"),
                    Forcibly = this.Forcibly
                });

                yield return(new BuildTarget
                {
                    CodeBlock = ReplacePlaceholder(addVueContent, type),
                    TargetPath = Path.Combine(path, "Add.vue"),
                    Forcibly = this.Forcibly
                });
            }
        }
Пример #6
0
 private string ReplacePlaceholder(string line, Type type)
 {
     return(line.Replace("{{AreaName}}", T4Help.GenerateNameSpace(type, ""))
            .Replace("{{ModuleName}}", type.Name)
            .Replace("{{Description}}", T4Help.GetClassSummary(type, this.XmlDocDir)));
 }
Пример #7
0
        public override IEnumerable <TargetInfo> GetTargetInfoList()
        {
            foreach (var type in GetTypes())
            {
                var exportAttr = type.GetCustomAttribute <ExportAttribute>();

                if (exportAttr == null || !exportAttr.ExportMarks.Contains(ExportMark.Controller))
                {
                    continue;
                }

                var spaceName = T4Help.GenerateNameSpace(type, null);
                var name      = type.Name;
                var summary   = T4Help.GetClassSummary(type, XmlDocDir);

                var baseNames = new List <string>();
                if (typeof(Entity.IHasManage).IsAssignableFrom(type))
                {
                    baseNames.Add($"BaseCURDController<{name}Dto>");
                }
                else
                {
                    baseNames.Add($"BaseController<{name}Dto>");
                }

                yield return(new TargetInfo()
                {
                    Summary = summary,
                    Path = $"{TargetPath}\\{spaceName}\\{type.Name}\\{type.Name}Controller.template.cs",
                    NamespaceName = $"FastFrame.WebHost.Controllers.{spaceName}",
                    ImportNames = new string[] {
                        //$"FastFrame.Entity.{spaceName}",
                        $"FastFrame.Application.{spaceName}",
                        //"FastFrame.Infrastructure.Permission",
                        //"FastFrame.Infrastructure.Interface"
                    },
                    CategoryName = "class",
                    Name = $"{name}Controller",
                    BaseNames = baseNames,
                    FieldInfos = new FieldInfo[] {
                        new FieldInfo()
                        {
                            TypeName = $"{name}Service", FieldName = "service"
                        }
                    },
                    Constructor = new Info.ConstructorInfo()
                    {
                        Parms = new ParameterInfo[] {
                            new ParameterInfo()
                            {
                                TypeName = $"{name}Service", DefineName = "service"
                            }
                        },
                        Super = new string[] { "service" },
                        CodeBlock = new string[] {
                            "this.service = service;"
                        }
                    },
                    //AttrInfos = new[] {
                    //    new AttrInfo()
                    //    {
                    //        Name="PermissionGroup",
                    //        Parameters=new string[]{ $"nameof({name})" , $"\"{summary}\"" }
                    //    }
                    //}
                });
            }
        }
Пример #8
0
        static void Main()
        {
            string typeName = "";
            string rootPath = new DirectoryInfo("../../../../").FullName;
            var    baseType = typeof(IEntity);
            var    types    = baseType
                              .Assembly
                              .GetTypes()
                              .Where(x => baseType.IsAssignableFrom(x) && x.IsClass && !x.IsAbstract)
                              .OrderBy(v => v.Namespace)
                              .ThenBy(v => v.Name)
                              .ToArray();

            var typeGroups = types
                             .Select((x, index) => new { Index = index + 1, Type = x })
                             .GroupBy(v => T4Help.GenerateNameSpace(v.Type, null));


START:

            Console.WriteLine("请输入要生成的类型:");
            foreach (var g in typeGroups)
            {
                Console.WriteLine();
                Console.WriteLine($"命名空间:{g.Key}");
                foreach (var item in g)
                {
                    var str = $"{item.Index}:{item.Type.Name}".PadRight(20, ' ');
                    Console.Write(str);

                    if (item.Index % 5 == 0)
                    {
                        Console.WriteLine();
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine("0:全部");

INPUT:
            Console.Write(">:");
            var inputIndex = Console.ReadLine();

            if (int.TryParse(inputIndex, out var intIndex) && intIndex >= 0 && types.Length > intIndex - 1)
            {
                typeName = intIndex == 0 ? "" : types[intIndex].Name;
            }
            else if (types.Any(v => v.Name == inputIndex))
            {
                typeName = inputIndex;
            }
            else
            {
                goto INPUT;
            }

            var codeBuildType = typeof(BaseCodeBuilder);
            var builds        = codeBuildType.Assembly
                                .GetTypes()
                                .Where(x => codeBuildType.IsAssignableFrom(x) && !x.IsAbstract);

            foreach (var item in builds)
            {
                var constructorInfo = item.GetConstructors().FirstOrDefault();
                var obj             = constructorInfo.Invoke(new object[] { rootPath, baseType });
                var builder         = (IBaseCodeBuilder)obj;

                RunWrite(builder, new string[] { typeName }, v => Console.WriteLine(Path.GetFullPath(v.TargetPath)));
            }

            goto START;
        }
Пример #9
0
        public Info.TargetInfo Build(Type type)
        {
            /*当前类型区域名称*/
            string areaName = T4Help.GenerateNameSpace(type, null);

            /*所依赖[引用]的类型*/
            IEnumerable <RelatedToAttribute> relatedTypes = type.GetProperties()
                                                            .Select(x => x.GetCustomAttribute <RelatedToAttribute>())
                                                            .Where(x => x != null);

            /*要导入的命名空间*/
            IEnumerable <string> importNames = relatedTypes
                                               .Select(x => T4Help.GenerateNameSpace(x.RelatedType, null))
                                               .Union(new[] { areaName })
                                               .SelectMany(x => new string[] { $"FastFrame.Entity.{x}", })
                                               .Union(new string[] {
                $"FastFrame.Infrastructure.Interface",
                "FastFrame.Infrastructure",
                "FastFrame.Repository",
                "FastFrame.Entity.Basis",
                "System.Linq",
                "Microsoft.EntityFrameworkCore",
                "System.Threading.Tasks"
            })
                                               .Union(type.GetProperties()
                                                      .Select(x => x.GetCustomAttribute <RelatedToAttribute>())
                                                      .Where(x => x != null)
                                                      .SelectMany(x => new[] { x.RelatedType.Namespace,
                                                                               $"FastFrame.Application.{T4Help.GenerateNameSpace(x.RelatedType,"")}" }))
                                               .Distinct();

            /*要导入的依赖*/
            var depends = relatedTypes
                          .Select(x => x.RelatedType.Name)
                          .Union(new[] { "User", type.Name })
                          .Distinct()
                          .Select(x => new { type = $"IRepository<{x}>", name = $"{x.ToFirstLower()}Repository" });


            return(new Info.TargetInfo()
            {
                NamespaceName = $"FastFrame.Application.{areaName}",
                ImportNames = importNames,
                Name = $"{type.Name}Service",
                CategoryName = "class",
                BaseNames = new string[] { $"BaseService<{type.Name}, {type.Name}Dto>" },
                FieldInfos = depends.Select(x => new FieldInfo()
                {
                    FieldName = x.name, TypeName = x.type
                }),
                Constructor = new Info.ConstructorInfo()
                {
                    Parms = depends.Select(x => new ParameterInfo()
                    {
                        TypeName = x.type, DefineName = x.name
                    }),
                    Super = new string[] { $"{type.Name.ToFirstLower()}Repository" },
                    CodeBlock = depends.Select(x => $"this.{x.name}={x.name};")
                },
                MethodInfos = GetMethods(type),
                Summary = $"{T4Help.GetClassSummary(type, XmlDocDir)} 服务实现",
                Path = $"{TargetPath}\\{areaName}\\{type.Name}\\{type.Name}Service.template.cs"
            });
        }