Fix support for Nullable (language version 8) (#25)

* Only emit #nullable when nullable is supported (>= 8.0)

* x

* is not
This commit is contained in:
Stef Heyenrath
2021-08-06 17:09:01 +02:00
committed by GitHub
parent 8d43c73816
commit 9dd2221f23
10 changed files with 56 additions and 34 deletions
@@ -11,8 +11,8 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal class PartialInterfacesGenerator : BaseGenerator, IFilesGenerator
{
public PartialInterfacesGenerator(Context context) :
base(context)
public PartialInterfacesGenerator(Context context, bool supportsNullable) :
base(context, supportsNullable)
{
}
@@ -30,7 +30,7 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators
var interfaceName = targetClassSymbol.ResolveInterfaceNameWithOptionalTypeConstraints(pd.InterfaceName);
var file = new FileData(
$"{pd.FileName}.g.cs",
$"{targetClassSymbol.GetFileName()}.g.cs",
CreatePartialInterfaceCode(pd.Namespace, targetClassSymbol, interfaceName, pd.ProxyAll)
);
@@ -48,7 +48,7 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators
// </auto-generated>
//----------------------------------------------------------------------------------------
#nullable enable
{(_supportsNullable ? "#nullable enable" : string.Empty)}
using System;
namespace {ns}
@@ -62,7 +62,7 @@ namespace {ns}
{GenerateEvents(targetClassSymbol)}
}}
}}
#nullable disable";
{(_supportsNullable ? "#nullable disable" : string.Empty)}";
private string GenerateProperties(INamedTypeSymbol targetClassSymbol, bool proxyAll)
{