Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MiniExcelLib.Core.Exceptions;

public class MiniExcelNotSerializableException(string message, MemberInfo member)
: InvalidOperationException(message)
{
public MemberInfo Member { get; } = member;
}
8 changes: 8 additions & 0 deletions src/MiniExcel.Core/Reflection/MiniExcelProperty.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using MiniExcelLib.Core.Exceptions;

namespace MiniExcelLib.Core.Reflection;

public abstract class Member;
Expand All @@ -12,6 +14,12 @@ public MiniExcelProperty(PropertyInfo property)
Name = property.Name;
Info = property;

if (property.GetIndexParameters().Length != 0)
{
const string msg = "Types containing indexers cannot be serialized. Please remove them or decorate them with MiniExcelIgnoreAttribute.";
throw new MiniExcelNotSerializableException(msg, property);
}

if (property.CanRead)
{
CanRead = true;
Expand Down
18 changes: 18 additions & 0 deletions tests/MiniExcel.Core.Tests/MiniExcelIssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3710,4 +3710,22 @@ public void TestIssue876()
_excelExporter.Export(outputPath.ToString(), sheets);
});
}

private class Issue880
{
public string Test { get; set; }
public string this[int i] => "";
}

[Fact]
public void TestIssue880_ShouldThrowNotSerializableException()
{
Issue880[] toExport = [new() { Test = "test" }];

Assert.Throws<MiniExcelNotSerializableException>(() =>
{
using var ms = new MemoryStream();
_excelExporter.Export(ms, toExport);
});
}
}
Loading