add MembersToIgnore

This commit is contained in:
Adam Hathcock
2024-05-21 13:03:43 +01:00
parent 894b5d5049
commit 5568a98e0b
15 changed files with 240 additions and 7 deletions
+2
View File
@@ -349,3 +349,5 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/tests/ProxyInterfaceSourceGeneratorTests/Destination/Disposable/*.g.cs
.idea/.idea.ProxyInterfaceSourceGenerator Solution/.idea/
@@ -7,5 +7,6 @@ namespace ProxyInterfaceConsumer
public int HouseNumber { get; set; }
public event EventHandler<EventArgs> MyEvent;
public int Weird { get; set; }
}
}
@@ -1,6 +1,8 @@
using ProxyInterfaceGenerator;
namespace ProxyInterfaceConsumer
{
[ProxyInterfaceGenerator.Proxy(typeof(Address))]
[ProxyInterfaceGenerator.Proxy(typeof(Address), false, ProxyClassAccessibility.Public, new []{"Weird"})]
public partial interface IAddress
{
}
@@ -28,7 +28,7 @@ public class Program
IClientContext cp = new ClientContextProxy(clientContext);
cp.Load<IWeb, Web>(cp.Web, w => w.Lists, w => w.Language, w => w.Author);
cp.Load<ProxyInterfaceConsumerForPnP.Interfaces.IWeb, Web>(cp.Web, w => w.Lists, w => w.Language, w => w.Author);
await cp.ExecuteQueryRetryAsync();
@@ -1,6 +1,8 @@
using ProxyInterfaceGenerator;
namespace ProxyInterfaceConsumer
{
[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.Person), ProxyClassAccessibility.Internal))]
[Proxy(typeof(Person), ProxyClassAccessibility.Internal)]
public partial interface IPerson
{
}
@@ -52,7 +52,7 @@ namespace ProxyInterfaceConsumer
b = 1;
}
public int In_Out_Ref2(in Address a, out Address b, ref Address c)
public int In_Out_Ref2(in IAddress a, out Address b, ref IAddress c)
{
b = new Address();
return 404;
@@ -27,6 +27,7 @@ namespace ProxyInterfaceGenerator
public Type Type {{ get; }}
public bool ProxyBaseClasses {{ get; }}
public ProxyClassAccessibility Accessibility {{ get; }}
public string[] MembersToIgnore {{ get; }}
public ProxyAttribute(Type type) : this(type, false, ProxyClassAccessibility.Public)
{{
@@ -40,11 +41,16 @@ namespace ProxyInterfaceGenerator
{{
}}
public ProxyAttribute(Type type, bool proxyBaseClasses, ProxyClassAccessibility accessibility)
public ProxyAttribute(Type type, bool proxyBaseClasses, ProxyClassAccessibility accessibility) : this(type, proxyBaseClasses, accessibility, Array.Empty<string>())
{{
}}
public ProxyAttribute(Type type, bool proxyBaseClasses, ProxyClassAccessibility accessibility, string[] membersToIgnore)
{{
Type = type;
ProxyBaseClasses = proxyBaseClasses;
Accessibility = accessibility;
MembersToIgnore = membersToIgnore;
}}
}}
@@ -12,7 +12,7 @@ internal static class AttributeArgumentListParser
{
public static ProxyInterfaceGeneratorAttributeArguments ParseAttributeArguments(AttributeArgumentListSyntax? argumentList, SemanticModel semanticModel)
{
if (argumentList is null || argumentList.Arguments.Count is < 1 or > 3)
if (argumentList is null || argumentList.Arguments.Count is < 1 or > 4)
{
throw new ArgumentException("The ProxyAttribute requires 1, 2 or 3 arguments.");
}
@@ -5,4 +5,5 @@ internal record ProxyInterfaceGeneratorAttributeArguments(string FullyQualifiedD
public bool ProxyBaseClasses { get; set; }
public ProxyClassAccessibility Accessibility { get; set; }
public string[] MembersToIgnore { get; set; } = Array.Empty<string>();
}
@@ -21,6 +21,7 @@ namespace ProxyInterfaceGenerator
public Type Type { get; }
public bool ProxyBaseClasses { get; }
public ProxyClassAccessibility Accessibility { get; }
public string[] MembersToIgnore { get; }
public ProxyAttribute(Type type) : this(type, false, ProxyClassAccessibility.Public)
{
@@ -34,11 +35,16 @@ namespace ProxyInterfaceGenerator
{
}
public ProxyAttribute(Type type, bool proxyBaseClasses, ProxyClassAccessibility accessibility)
public ProxyAttribute(Type type, bool proxyBaseClasses, ProxyClassAccessibility accessibility) : this(type, proxyBaseClasses, accessibility, Array.Empty<string>())
{
}
public ProxyAttribute(Type type, bool proxyBaseClasses, ProxyClassAccessibility accessibility, string[] membersToIgnore)
{
Type = type;
ProxyBaseClasses = proxyBaseClasses;
Accessibility = accessibility;
MembersToIgnore = membersToIgnore;
}
}
@@ -0,0 +1,132 @@
[
{
HintName: ProxyInterfaceGenerator.Extra.g.cs,
Source:
//----------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//----------------------------------------------------------------------------------------
using System;
namespace ProxyInterfaceGenerator
{
[AttributeUsage(AttributeTargets.Interface)]
internal sealed class ProxyAttribute : Attribute
{
public Type Type { get; }
public bool ProxyBaseClasses { get; }
public ProxyClassAccessibility Accessibility { get; }
public string[] MembersToIgnore { get; }
public ProxyAttribute(Type type) : this(type, false, ProxyClassAccessibility.Public)
{
}
public ProxyAttribute(Type type, bool proxyBaseClasses) : this(type, proxyBaseClasses, ProxyClassAccessibility.Public)
{
}
public ProxyAttribute(Type type, ProxyClassAccessibility accessibility) : this(type, false, accessibility)
{
}
public ProxyAttribute(Type type, bool proxyBaseClasses, ProxyClassAccessibility accessibility) : this(type, proxyBaseClasses, accessibility, Array.Empty<string>())
{
}
public ProxyAttribute(Type type, bool proxyBaseClasses, ProxyClassAccessibility accessibility, string[] membersToIgnore)
{
Type = type;
ProxyBaseClasses = proxyBaseClasses;
Accessibility = accessibility;
MembersToIgnore = membersToIgnore;
}
}
[Flags]
internal enum ProxyClassAccessibility
{
Public = 0,
Internal = 1
}
}
},
{
HintName: ProxyInterfaceSourceGeneratorTests.Source.IFoo2.g.cs,
Source:
//----------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//----------------------------------------------------------------------------------------
#nullable enable
using System;
namespace ProxyInterfaceSourceGeneratorTests.Source
{
public partial interface IFoo2
{
global::ProxyInterfaceSourceGeneratorTests.Source.Foo2 _Instance { get; }
global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] Foos { get; set; }
global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] DoSomethingAndGetAnArrayOfFoos();
}
}
#nullable restore
},
{
HintName: ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy.g.cs,
Source:
//----------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by https://github.com/StefH/ProxyInterfaceSourceGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//----------------------------------------------------------------------------------------
#nullable enable
using System;
namespace ProxyInterfaceSourceGeneratorTests.Source
{
public partial class Foo2Proxy : global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2
{
public global::ProxyInterfaceSourceGeneratorTests.Source.Foo2 _Instance { get; }
public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] Foos { get => Mapster.TypeAdapter.Adapt<global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[]>(_Instance.Foos); set => _Instance.Foos = Mapster.TypeAdapter.Adapt<ProxyInterfaceSourceGeneratorTests.Source.Foo2[]>(value); }
public global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[] DoSomethingAndGetAnArrayOfFoos()
{
var result_1603865878 = _Instance.DoSomethingAndGetAnArrayOfFoos();
return Mapster.TypeAdapter.Adapt<global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2[]>(result_1603865878);
}
public Foo2Proxy(global::ProxyInterfaceSourceGeneratorTests.Source.Foo2 instance)
{
_Instance = instance;
Mapster.TypeAdapterConfig<global::ProxyInterfaceSourceGeneratorTests.Source.Foo2, global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2>.NewConfig().ConstructUsing(instance1325374861 => new global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy(instance1325374861));
Mapster.TypeAdapterConfig<global::ProxyInterfaceSourceGeneratorTests.Source.IFoo2, global::ProxyInterfaceSourceGeneratorTests.Source.Foo2>.NewConfig().MapWith(proxy1047178445 => ((global::ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy) proxy1047178445)._Instance);
}
}
}
#nullable restore
}
]
@@ -86,6 +86,44 @@ public class ProxyInterfaceSourceGeneratorTest
return Verify(results);
}
[Fact]
public Task GenerateFiles_ForClassWithIgnores()
{
// Arrange
var fileNames = new[]
{
"ProxyInterfaceSourceGeneratorTests.Source.IFoo2.g.cs",
"ProxyInterfaceSourceGeneratorTests.Source.Foo2Proxy.g.cs"
};
var path = "./Source/IFoo2.cs";
var sourceFile = new SourceFile
{
Path = path,
Text = File.ReadAllText(path),
AttributeToAddToInterface = new ExtraAttribute
{
Name = "ProxyInterfaceGenerator.Proxy",
ArgumentList = "typeof(ProxyInterfaceSourceGeneratorTests.Source.Foo2)"
}
};
// Act
var result = _sut.Execute(new[]
{
sourceFile
});
// Assert
result.Valid.Should().BeTrue();
result.Files.Should().HaveCount(fileNames.Length + 1);
// Verify
var results = result.GeneratorDriver.GetRunResult().Results.First().GeneratedSources;
return Verify(results);
}
[Fact]
public void GenerateFiles_ForGenericType_Should_GenerateCorrectFiles()
{
@@ -49,6 +49,12 @@
<Compile Update="Source\AkkaActor\*.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Update="Source\Foo2.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Update="Source\IFoo2.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
</ItemGroup>
<ItemGroup>
@@ -0,0 +1,31 @@
namespace ProxyInterfaceSourceGeneratorTests.Source;
public class Foo2
{
//public Bar DoSomethingAndGetABar()
//{
// return new Bar();
//}
//public Bar[] DoSomethingAndGetAnArrayOfBars()
//{
// return new[] { new Bar() };
//}
//public Foo DoSomethingAndGetAFoo()
//{
// return new Foo();
//}
public Foo2[] Foos { get; set; }
public Foo2[] DoSomethingAndGetAnArrayOfFoos()
{
return new[] { new Foo2() };
}
//public List<Foo> DoSomethingAndGetAListOfFoos()
//{
// return new[] { new Foo() }.ToList();
//}
}
@@ -0,0 +1,6 @@
namespace ProxyInterfaceSourceGeneratorTests.Source
{
public partial interface IFoo2
{
}
}