Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Mapster.Tool/ExtensionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class ExtensionOptions
[Option('b', "baseNamespace", Required = false, HelpText = "Provide base namespace to generate nested output & namespace")]
public string? BaseNamespace { get; set; }

[Option('s', "skipExisting", Required = false, HelpText = "Set true to skip generating already existing files")]
public bool SkipExistingFiles { get; set; }

[Usage(ApplicationAlias = "dotnet mapster extension")]
public static IEnumerable<Example> Examples =>
new List<Example>
Expand Down
3 changes: 3 additions & 0 deletions src/Mapster.Tool/MapperOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class MapperOptions
[Option('b', "baseNamespace", Required = false, HelpText = "Provide base namespace to generate nested output & namespace")]
public string? BaseNamespace { get; set; }

[Option('s', "skipExisting", Required = false, HelpText = "Set true to skip generating already existing files")]
public bool SkipExistingFiles { get; set; }

[Usage(ApplicationAlias = "dotnet mapster mapper")]
public static IEnumerable<Example> Examples =>
new List<Example>
Expand Down
3 changes: 3 additions & 0 deletions src/Mapster.Tool/ModelOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class ModelOptions
[Option('b', "baseNamespace", Required = false, HelpText = "Provide base namespace to generate nested output & namespace")]
public string? BaseNamespace { get; set; }

[Option('s', "skipExisting", Required = false, HelpText = "Set true to skip generating already existing files")]
public bool SkipExistingFiles { get; set; }

[Usage(ApplicationAlias = "dotnet mapster model")]
public static IEnumerable<Example> Examples =>
new List<Example>
Expand Down
27 changes: 24 additions & 3 deletions src/Mapster.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ private static void GenerateMappers(MapperOptions opt)
IsInternal = attr.IsInternal,
PrintFullTypeName = opt.PrintFullTypeName,
};

var path = GetOutput(opt.Output, segments, definitions.TypeName);
if (opt.SkipExistingFiles && File.Exists(path))
{
Console.WriteLine($"Skipped: {type.FullName}. Mapper {definitions.TypeName} already exists.");
continue;
}

var translator = new ExpressionTranslator(definitions);
var interfaces = type.GetAllInterfaces();
foreach (var @interface in interfaces)
Expand Down Expand Up @@ -126,7 +134,6 @@ private static void GenerateMappers(MapperOptions opt)
}

var code = translator.ToString();
var path = GetOutput(opt.Output, segments, definitions.TypeName);
WriteFile(code, path);
}
}
Expand Down Expand Up @@ -189,6 +196,14 @@ private static void CreateModel(ModelOptions opt, Type type, AdaptAttributeBuild
IsRecordType = opt.IsRecordType,
NullableContext = GetTypeNullableContext(type),
};

var path = GetOutput(opt.Output, segments, definitions.TypeName);
if (opt.SkipExistingFiles && File.Exists(path))
{
Console.WriteLine($"Skipped: {type.FullName}. Model {definitions.TypeName} already exists.");
return;
}

var translator = new ExpressionTranslator(definitions);
var isAdaptTo = attr is AdaptToAttribute;
var isTwoWays = attr is AdaptTwoWaysAttribute;
Expand Down Expand Up @@ -252,7 +267,6 @@ private static void CreateModel(ModelOptions opt, Type type, AdaptAttributeBuild
}

var code = translator.ToString();
var path = GetOutput(opt.Output, segments, definitions.TypeName);
WriteFile(code, path);

static Type getPropType(MemberInfo mem)
Expand Down Expand Up @@ -428,6 +442,14 @@ private static void GenerateExtensions(ExtensionOptions opt)
IsInternal = mapperAttr.IsInternal,
PrintFullTypeName = opt.PrintFullTypeName,
};

var path = GetOutput(opt.Output, segments, definitions.TypeName);
if (opt.SkipExistingFiles && File.Exists(path))
{
Console.WriteLine($"Skipped: {type.FullName}. Extension class {definitions.TypeName} already exists.");
continue;
}

var translator = new ExpressionTranslator(definitions);

foreach (var builder in builders)
Expand Down Expand Up @@ -460,7 +482,6 @@ private static void GenerateExtensions(ExtensionOptions opt)
}

var code = translator.ToString();
var path = GetOutput(opt.Output, segments, definitions.TypeName);
WriteFile(code, path);
}
}
Expand Down