From 44bc08015cdcf8c719725cd761e25e4986ba1ddf Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 8 May 2022 18:53:25 +0200 Subject: [PATCH] . (#35) --- .../FileGenerators/BaseGenerator.cs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs b/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs index 29247e7..d495ae9 100644 --- a/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs +++ b/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs @@ -105,11 +105,6 @@ internal abstract class BaseGenerator constraints.Add("struct"); } - if (typeParameterSymbol.HasConstructorConstraint) - { - constraints.Add("new()"); - } - foreach (var namedTypeSymbol in typeParameterSymbol.ConstraintTypes.OfType()) { if (replaceIt) @@ -122,14 +117,20 @@ internal abstract class BaseGenerator } } - if (!constraints.Any()) + // The new() constraint must be the last constraint specified. + if (typeParameterSymbol.HasConstructorConstraint) { - constraint = null; - return false; + constraints.Add("new()"); } - constraint = new(typeParameterSymbol.Name, constraints); - return true; + if (constraints.Any()) + { + constraint = new(typeParameterSymbol.Name, constraints); + return true; + } + + constraint = null; + return false; } protected string GetReplacedType(ITypeSymbol typeSymbol, out bool isReplaced)