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
15 changes: 15 additions & 0 deletions src/MiniExcel/Exceptions/MiniExcelNotSerializableException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Reflection;

namespace MiniExcelLibs.Exceptions
{
public class MiniExcelNotSerializableException : InvalidOperationException
{
public MemberInfo Member { get; }

public MiniExcelNotSerializableException(string message, MemberInfo member) : base(message)
{
Member = member;
}
}
}
9 changes: 8 additions & 1 deletion src/MiniExcel/Reflection/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
using MiniExcelLibs.Exceptions;

namespace MiniExcelLibs
{
Expand All @@ -18,7 +19,13 @@ public Property(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/MiniExcelTests/MiniExcelIssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4719,4 +4719,22 @@ public void TestIssue876()
MiniExcel.SaveAs(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();
ms.SaveAs(toExport);
});
}
}
Loading