-
Notifications
You must be signed in to change notification settings - Fork 392
Closed
Description
First, thanks for this awsome tool !!!
Issue description
When trying to generate code referencing OTHER_ASSEMBLY in fluent api, nothing happens.
Steps to reproduce the issue
- Install Mapster.Tool in a project
- Copy "Generate automatically on build" tags on csproj file
- Create a POCO class inside OTHER_ASSEMBLY.
- Create a "fluent api configuration class" inside the project:
config.AdaptTo("[name]Dto")
.ForAllTypesInNamespace(OTHER_ASSEMBLY, "POCO..Namespace");- Build
What's the expected result?
- Generated Dtos in Models Folder inside current Assembly.
What's the actual result?
- nothing happens
Additional details
I review the code. Maybe I'm wrong, but in this method:
Mapster/src/Mapster.Tool/Program.cs
Lines 116 to 137 in d7a8397
| private static void GenerateModels(ModelOptions opt) | |
| { | |
| using var dynamicContext = new AssemblyResolver(Path.GetFullPath(opt.Assembly)); | |
| var assembly = dynamicContext.Assembly; | |
| var codeGenConfig = new CodeGenerationConfig(); | |
| codeGenConfig.Scan(assembly); | |
| foreach (var type in assembly.GetTypes()) | |
| { | |
| var builders = type.GetAdaptAttributeBuilders(codeGenConfig) | |
| .Where(it => !string.IsNullOrEmpty(it.Attribute.Name) && it.Attribute.Name != "[name]") | |
| .ToList(); | |
| if (builders.Count == 0) | |
| continue; | |
| Console.WriteLine($"Processing: {type.FullName}"); | |
| foreach (var builder in builders) | |
| { | |
| CreateModel(opt, type, builder); | |
| } | |
| } | |
| } |
the current ASSEMBLY is used, but inside the codeGenConfig.Scan method:
Mapster/src/Mapster.Tool/Extensions.cs
Lines 175 to 186 in d7a8397
| public static void Scan(this CodeGenerationConfig config, Assembly assembly) | |
| { | |
| var registers = assembly.GetTypes() | |
| .Where(x => typeof(ICodeGenerationRegister).GetTypeInfo().IsAssignableFrom(x.GetTypeInfo()) && | |
| x.GetTypeInfo().IsClass && !x.GetTypeInfo().IsAbstract) | |
| .Select(type => (ICodeGenerationRegister) Activator.CreateInstance(type)!); | |
| foreach (var register in registers) | |
| { | |
| register.Register(config); | |
| } | |
| } |
when Register is called, my ForAllTypesInNamespace with OTHER_ASSEMBLY is called.
So, I think the problem is in the foreach of the GenerateModels method. There, the GetTypes() of the current ASSEMBLY is called (ignoring completely the OTHER_ASSEMBLY types).
Thanks in advance
Metadata
Metadata
Assignees
Labels
No labels