File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
tests/MiniExcel.Core.Tests Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ namespace MiniExcelLib . Core . Exceptions ;
2+
3+ public class MiniExcelNotSerializableException ( string message , MemberInfo member )
4+ : InvalidOperationException ( message )
5+ {
6+ public MemberInfo Member { get ; } = member ;
7+ }
Original file line number Diff line number Diff line change 1+ using MiniExcelLib . Core . Exceptions ;
2+
13namespace MiniExcelLib . Core . Reflection ;
24
35public abstract class Member ;
@@ -12,6 +14,12 @@ public MiniExcelProperty(PropertyInfo property)
1214 Name = property . Name ;
1315 Info = property ;
1416
17+ if ( property . GetIndexParameters ( ) . Length != 0 )
18+ {
19+ const string msg = "Types containing indexers cannot be serialized. Please remove them or decorate them with MiniExcelIgnoreAttribute." ;
20+ throw new MiniExcelNotSerializableException ( msg , property ) ;
21+ }
22+
1523 if ( property . CanRead )
1624 {
1725 CanRead = true ;
Original file line number Diff line number Diff line change @@ -3710,4 +3710,22 @@ public void TestIssue876()
37103710 _excelExporter . Export ( outputPath . ToString ( ) , sheets ) ;
37113711 } ) ;
37123712 }
3713+
3714+ private class Issue880
3715+ {
3716+ public string Test { get ; set ; }
3717+ public string this [ int i ] => "" ;
3718+ }
3719+
3720+ [ Fact ]
3721+ public void TestIssue880_ShouldThrowNotSerializableException ( )
3722+ {
3723+ Issue880 [ ] toExport = [ new ( ) { Test = "test" } ] ;
3724+
3725+ Assert . Throws < MiniExcelNotSerializableException > ( ( ) =>
3726+ {
3727+ using var ms = new MemoryStream ( ) ;
3728+ _excelExporter . Export ( ms , toExport ) ;
3729+ } ) ;
3730+ }
37133731}
You can’t perform that action at this time.
0 commit comments