diff --git a/DecoratorGenerator.UnitTests/Tests.cs b/DecoratorGenerator.UnitTests/Tests.cs index f3218bb..6d42358 100644 --- a/DecoratorGenerator.UnitTests/Tests.cs +++ b/DecoratorGenerator.UnitTests/Tests.cs @@ -5,6 +5,7 @@ using SampleLibrary.Deep.Nesteds; using System.Reflection; using System.Text; +using TestLibrary; using VerifyCS = DecoratorGenerator.UnitTests.CSharpSourceGeneratorVerifier; namespace DecoratorGenerator.UnitTests; @@ -41,6 +42,29 @@ public async Task OneInterface() { }.RunAsync(); } + [Test] + public async Task OneInterface_Internal() { + var source = await ReadCSharpFile(true); + var generated = await ReadCSharpFile(true); + + await new VerifyCS.Test + { + TestState = { + ReferenceAssemblies = ReferenceAssemblies.Net.Net90, + AdditionalReferences = + { + implementationAssembly, + GetAssembly("TestLibrary") + }, + Sources = { source }, + GeneratedSources = + { + (typeof(Main), "InternalTypeDecorator.generated.cs", SourceText.From(generated, Encoding.UTF8, SourceHashAlgorithm.Sha256)), + }, + }, + }.RunAsync(); + } + [Test] public async Task OneInterface_Properties() { var source = await ReadCSharpFile(true); diff --git a/DecoratorGenerator/OutputGenerator.cs b/DecoratorGenerator/OutputGenerator.cs index 79fc462..d69989a 100644 --- a/DecoratorGenerator/OutputGenerator.cs +++ b/DecoratorGenerator/OutputGenerator.cs @@ -8,6 +8,7 @@ namespace DecoratorGenerator internal static class OutputGenerator { public static (string source, string className) GenerateOutputs(INamedTypeSymbol @interface) { + var interfaceAccessModifier = @interface.DeclaredAccessibility.ToString().ToLower(); var className = $"{@interface.Name.Substring(1)}Decorator"; var formattedConstraintTypes = FormatInterfaceConstraintTypes(@interface); var formattedConstraints = CreateFormattedConstraints(@interface.TypeParameters); @@ -25,7 +26,7 @@ public static (string source, string className) GenerateOutputs(INamedTypeSymbol #nullable restore namespace {@interface.ContainingNamespace.ToDisplayString()}; -public abstract class {className}{formattedConstraintTypes} : {@interface.Name}{formattedConstraintTypes}{(formattedConstraints != string.Empty ? $@" {formattedConstraints}" : string.Empty)} +{interfaceAccessModifier} abstract class {className}{formattedConstraintTypes} : {@interface.Name}{formattedConstraintTypes}{(formattedConstraints != string.Empty ? $@" {formattedConstraints}" : string.Empty)} {{ private {@interface.Name}{formattedConstraintTypes} {targetFieldName}; diff --git a/TestLibrary/IInternalType.cs b/TestLibrary/IInternalType.cs new file mode 100644 index 0000000..c833b9e --- /dev/null +++ b/TestLibrary/IInternalType.cs @@ -0,0 +1,9 @@ +using DecoratorGenerator; + +namespace TestLibrary; + +[Decorate] +internal interface IInternalType +{ + +} diff --git a/TestLibrary/InternalTypeDecorator.generated.cs b/TestLibrary/InternalTypeDecorator.generated.cs new file mode 100644 index 0000000..11e3400 --- /dev/null +++ b/TestLibrary/InternalTypeDecorator.generated.cs @@ -0,0 +1,16 @@ +// +#nullable restore +namespace TestLibrary; + +internal abstract class InternalTypeDecorator : IInternalType +{ + private IInternalType internalType; + + protected InternalTypeDecorator(IInternalType internalType) { + this.internalType = internalType; + } + + + + +}