diff --git a/.gitignore b/.gitignore
index df37204..5acd52d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-IntelliJ IDEA
+IntelliJ IDEA
*.swp
*.*~
project.lock.json
@@ -38,4 +38,6 @@ msbuild.wrn
.vs/
#Generator logs
-AutomaticInterfaceGenerator_log.txt
\ No newline at end of file
+AutomaticInterfaceGenerator_log.txt
+
+*.received.*
\ No newline at end of file
diff --git a/AutomaticInterface/AutomaticInterface/AutomaticInterface.csproj b/AutomaticInterface/AutomaticInterface/AutomaticInterface.csproj
index 5efb0d5..4de54bd 100644
--- a/AutomaticInterface/AutomaticInterface/AutomaticInterface.csproj
+++ b/AutomaticInterface/AutomaticInterface/AutomaticInterface.csproj
@@ -25,7 +25,7 @@
MIT
True
latest-Recommended
- 5.1.2
+ 5.1.3
README.md
true
1701;1702;NU5128
diff --git a/AutomaticInterface/AutomaticInterface/RoslynExtensions.cs b/AutomaticInterface/AutomaticInterface/RoslynExtensions.cs
index b31827a..09a77ee 100644
--- a/AutomaticInterface/AutomaticInterface/RoslynExtensions.cs
+++ b/AutomaticInterface/AutomaticInterface/RoslynExtensions.cs
@@ -64,6 +64,12 @@ SymbolDisplayFormat typeDisplayFormat
isFirstConstraint = false;
}
+ if (typeParameterSymbol.HasNotNullConstraint)
+ {
+ constraints += "notnull";
+ isFirstConstraint = false;
+ }
+
foreach (var constraintType in typeParameterSymbol.ConstraintTypes)
{
// if not first constraint prepend with comma
diff --git a/AutomaticInterface/Tests/Methods/Methods.WorksWithGenericTypeConstraintsForMethods.verified.txt b/AutomaticInterface/Tests/Methods/Methods.WorksWithGenericTypeConstraintsForMethods.verified.txt
new file mode 100644
index 0000000..f7bace4
--- /dev/null
+++ b/AutomaticInterface/Tests/Methods/Methods.WorksWithGenericTypeConstraintsForMethods.verified.txt
@@ -0,0 +1,18 @@
+//--------------------------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+//
+//--------------------------------------------------------------------------------------------------
+
+namespace AutomaticInterfaceExample
+{
+ [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
+ public partial interface IDemoClass
+ {
+ ///
+ IQueryable AddFilter(IQueryable qry) where T : notnull;
+
+ }
+}
diff --git a/AutomaticInterface/Tests/Methods/Methods.cs b/AutomaticInterface/Tests/Methods/Methods.cs
index 6542a4d..957f8e2 100644
--- a/AutomaticInterface/Tests/Methods/Methods.cs
+++ b/AutomaticInterface/Tests/Methods/Methods.cs
@@ -329,6 +329,27 @@ public string CMethod(string x, string y)
await Verify(Infrastructure.GenerateCode(code));
}
+ [Fact]
+ public async Task WorksWithGenericTypeConstraintsForMethods()
+ {
+ const string code = """
+
+ using AutomaticInterface;
+
+ namespace AutomaticInterfaceExample;
+
+ [GenerateAutomaticInterface]
+ public class DemoClass
+ {
+ public IQueryable AddFilter(IQueryable qry) where T : notnull => qry;
+ }
+
+
+ """;
+
+ await Verify(Infrastructure.GenerateCode(code));
+ }
+
[Fact]
public async Task GeneratesOverloadedMethodInterface()
{
diff --git a/AutomaticInterface/Tests/test.cs b/AutomaticInterface/Tests/test.cs
new file mode 100644
index 0000000..1357849
--- /dev/null
+++ b/AutomaticInterface/Tests/test.cs
@@ -0,0 +1,13 @@
+namespace Tests;
+
+public interface Itest
+{
+ IQueryable AddFilter(IQueryable qry)
+ where T : notnull;
+}
+
+public class test : Itest
+{
+ public IQueryable AddFilter(IQueryable qry)
+ where T : notnull => qry;
+}
diff --git a/README.md b/README.md
index 4bf2e76..2789cac 100644
--- a/README.md
+++ b/README.md
@@ -186,6 +186,10 @@ Note that we use [Verify](https://github.com/VerifyTests/Verify) for testing. It
## Changelog
+### 5.1.3.
+
+- Emit `notnull` type constraints on generic type parameters
+
### 5.1.2
- Fixing enums in method signatures