Skip to content

Commit

Permalink
Ignore indexers from row types in source generator
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinungf committed Oct 5, 2024
1 parent 731af77 commit 360e686
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//HintName: MyNamespace.MyContext.g.cs
// <auto-generated />
#nullable enable
using SpreadCheetah;
using SpreadCheetah.SourceGeneration;
using SpreadCheetah.Styling;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace MyNamespace
{
public partial class MyContext
{
private static MyContext? _default;
public static MyContext Default => _default ??= new MyContext();

public MyContext()
{
}

private WorksheetRowTypeInfo<MyNamespace.MyClass>? _MyClass;
public WorksheetRowTypeInfo<MyNamespace.MyClass> MyClass => _MyClass
??= EmptyWorksheetRowContext.CreateTypeInfo<MyNamespace.MyClass>();

private static DataCell ConstructTruncatedDataCell(string? value, int truncateLength)
{
return value is null || value.Length <= truncateLength
? new DataCell(value)
: new DataCell(value.AsMemory(0, truncateLength));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,27 @@ public partial class MyContext : WorksheetRowContext;
// Act & Assert
return TestHelper.CompileAndVerify<WorksheetRowGenerator>(source);
}

[Fact]
public Task PropertyType_ClassWithIndexer()
{
// Arrange
const string source = """
using SpreadCheetah.SourceGeneration;
using System;
namespace MyNamespace;
public class MyClass
{
public int this[int index] => index;
}
[WorksheetRow(typeof(MyClass))]
public partial class MyContext : WorksheetRowContext;
""";

// Act & Assert
return TestHelper.CompileAndVerify<WorksheetRowGenerator>(source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static bool IsInstancePropertyWithPublicGetter(
{
DeclaredAccessibility: Accessibility.Public,
IsStatic: false,
IsIndexer: false,
IsWriteOnly: false
};
}
Expand Down

0 comments on commit 360e686

Please sign in to comment.