-
Notifications
You must be signed in to change notification settings - Fork 59
Add example for a generator respecting nullability #190
Conversation
src/CodeGeneration.Roslyn.Tests/OtherFolder/NullableGeneratorTests.cs
Outdated
Show resolved
Hide resolved
src/CodeGeneration.Roslyn.Tests/CodeGeneration.Roslyn.Tests.csproj
Outdated
Show resolved
Hide resolved
So, this example is fine and a good addition. It doesn't fix #183, however. That would require passing around both |
The following code/file is generated // ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
namespace CodeGeneration.Roslyn.Tests.OtherFolder
{
using System;
using System.Diagnostics;
using CodeGeneration.Roslyn.Tests.Generators;
using Xunit;
public partial class NullableEnabled
{
#nullable enable
public string? DoSomething(string? value)
{
return value;
}
#nullable restore
#nullable enable
public string? DoSomethingStrict(string value)
{
return value;
}
#nullable restore
}
}
namespace CodeGeneration.Roslyn.Tests.OtherFolder
{
using System;
using System.Diagnostics;
using CodeGeneration.Roslyn.Tests.Generators;
using Xunit;
public partial class NullableDisabled
{
public string DoSomething(string value)
{
return value;
}
public string DoSomethingStrict(string value)
{
return value;
}
}
} |
I think that since we need to check that the warning is generated (if we don't specify So, inputs and outputs are just strings that contain source code, and we could validate that the resulting compilation has no errors/warnings by checking diagnostics. It may be probably done in another PR, though. |
This project is getting archived in favor of Source Generators. See #229 |
This PR adds a generator respecting the nullability context of the class.
For the class
NullableEnabled
where#nullable enable
it generates a methodstring? DoSomething(string?)
. In the generated code nullable is enabled and restored properly.For the class
NullableDisabled
where#nullable disable
it generates a methodstring DoSomething(string)
.can solve issue #183 . I did not read the whole conversation properly 🤨