Update [AutoConstructor] attribute to ignore generated fields

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-29 12:58:19 +02:00
1 親 459517a181
コミット 7d14403632
2ファイル変更
+32 -1

検索条件に一致するファイルはありません

+1 -1
ファイルの表示
@@ -59,7 +59,7 @@ public sealed partial class AutoConstructorGenerator : IIncrementalGenerator
{
return (
from fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>()
where fieldSymbol is { IsConst: false, IsStatic: false, IsFixedSizeBuffer: false }
where fieldSymbol is { IsConst: false, IsStatic: false, IsFixedSizeBuffer: false, IsImplicitlyDeclared: false }
let typeName = fieldSymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
select new ParameterInfo(typeName, fieldSymbol.Name)).ToImmutableArray();
}
+31
ファイルの表示
@@ -54,4 +54,35 @@ public unsafe partial class AutoConstructorAttributeTests
Assert.AreEqual(instance.a, a);
Assert.AreEqual(instance.b, b);
}
public partial interface IAnotherInterface
{
public int B { get; }
public void Foo();
}
public partial struct AnotherStruct : IAnotherInterface
{
public int a;
public float b;
int IAnotherInterface.B { get; }
void IAnotherInterface.Foo()
{
}
}
[TestMethod]
public void GenerateConstructorWithExplicitInterfaceMembers()
{
int a = 42;
float b = 3.14f;
AnotherStruct instance = new(a, b);
Assert.AreEqual(instance.a, a);
Assert.AreEqual(instance.b, b);
}
}