Skip to content

Commit

Permalink
[C#] Fix using en trop si requiredNonNullable
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Sep 9, 2024
1 parent ab6927e commit 2f1fe4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion TopModel.Generator.Csharp/CSharpClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,10 @@ protected virtual void GenerateUsings(CSharpWriter w, Class item, string tag)
usings.Add("System.ComponentModel");
}

if (item.Properties.Any(p => p.Required || p.PrimaryKey || Config.GetType(p)?.TrimEnd('?') == "string" && p.Domain.Length != null))
if (item.Properties.Any(p =>
p.Required && !Config.RequiredNonNullable(tag)
|| p.PrimaryKey
|| Config.GetType(p)?.TrimEnd('?') == "string" && p.Domain.Length != null))
{
usings.Add("System.ComponentModel.DataAnnotations");
}
Expand Down
2 changes: 1 addition & 1 deletion TopModel.Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void HandleFile(FileInfo file)
{
var generatorsPath = Path.Combine(new FileInfo(Assembly.GetEntryAssembly()!.Location).DirectoryName!, "../../../..");
var modules = Directory.GetFileSystemEntries(generatorsPath).Where(e => e.Contains("TopModel.Generator.") && !e.Contains("TopModel.Generator.Core"));
config.CustomGenerators.AddRange(modules.Select(m => Path.GetRelativePath(config.ModelRoot, m)));
config.CustomGenerators.AddRange(modules.Select(m => Path.GetRelativePath(config.ModelRoot, m).Replace("\\", "/")));
}

if (updateMode == "all")
Expand Down

0 comments on commit 2f1fe4a

Please sign in to comment.