always write nullable context
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
@@ -159,6 +160,36 @@ public class MethodGenerationTests
|
||||
var _ = _sut.StringMethod();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringMethodNullable_IsImplemented()
|
||||
{
|
||||
var method =
|
||||
typeof(IMethodsTestService).GetMethod(nameof(MethodsTestService.StringMethodNullable))
|
||||
?? throw new InvalidOperationException();
|
||||
|
||||
method.Should().NotBeNull();
|
||||
method.ReturnType.Should().Be(typeof(string));
|
||||
IsNullable(method.ReturnType).Should().BeTrue();
|
||||
|
||||
var parameters = method.GetParameters();
|
||||
parameters.Should().BeEmpty();
|
||||
|
||||
var _ = _sut.StringMethod();
|
||||
}
|
||||
|
||||
private static bool IsNullable(Type type)
|
||||
{
|
||||
var nullableContextAttribute = type.GetCustomAttribute<NullableContextAttribute>();
|
||||
|
||||
// NullableContextAttribute exists and has a flag indicating nullable annotations
|
||||
if (nullableContextAttribute != null && nullableContextAttribute.Flag == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenericVoidMethod_IsImplemented()
|
||||
{
|
||||
@@ -312,6 +343,11 @@ internal class MethodsTestService : IMethodsTestService
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string? StringMethodNullable()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void GenericVoidMethod<TX, TY>() { }
|
||||
|
||||
public void GenericVoidMethodWithGenericParam<TX, TY>(TX a) { }
|
||||
|
||||
Reference in New Issue
Block a user