File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Reflection ;
3+
4+ namespace MiniExcelLibs . Exceptions
5+ {
6+ public class MiniExcelNotSerializableException : InvalidOperationException
7+ {
8+ public MemberInfo Member { get ; }
9+
10+ public MiniExcelNotSerializableException ( string message , MemberInfo member ) : base ( message )
11+ {
12+ Member = member ;
13+ }
14+ }
15+ }
Original file line number Diff line number Diff line change 22using System . Collections . Concurrent ;
33using System . Linq ;
44using System . Reflection ;
5+ using MiniExcelLibs . Exceptions ;
56
67namespace MiniExcelLibs
78{
@@ -18,7 +19,13 @@ public Property(PropertyInfo property)
1819 {
1920 Name = property . Name ;
2021 Info = property ;
21-
22+
23+ if ( property . GetIndexParameters ( ) . Length != 0 )
24+ {
25+ const string msg = "Types containing indexers cannot be serialized. Please remove them or decorate them with MiniExcelIgnoreAttribute." ;
26+ throw new MiniExcelNotSerializableException ( msg , property ) ;
27+ }
28+
2229 if ( property . CanRead )
2330 {
2431 CanRead = true ;
Original file line number Diff line number Diff line change @@ -4719,4 +4719,22 @@ public void TestIssue876()
47194719 MiniExcel . SaveAs ( outputPath . ToString ( ) , sheets ) ;
47204720 } ) ;
47214721 }
4722+
4723+ private class Issue880
4724+ {
4725+ public string Test { get ; set ; }
4726+ public string this [ int i ] => "" ;
4727+ }
4728+
4729+ [ Fact ]
4730+ public void TestIssue880_ShouldThrowNotSerializableException ( )
4731+ {
4732+ Issue880 [ ] toExport = [ new ( ) { Test = "test" } ] ;
4733+
4734+ Assert . Throws < MiniExcelNotSerializableException > ( ( ) =>
4735+ {
4736+ using var ms = new MemoryStream ( ) ;
4737+ ms . SaveAs ( toExport ) ;
4738+ } ) ;
4739+ }
47224740}
You can’t perform that action at this time.
0 commit comments