@@ -70,7 +70,7 @@ internal static PropertyDescriptorCollection GetProperties(DapperTable table, ID
70
70
{
71
71
var type = row != null && row . TryGetValue ( names [ i ] , out var value ) && value != null
72
72
? value . GetType ( ) : typeof ( object ) ;
73
- arr [ i ] = new RowBoundPropertyDescriptor ( type , names [ i ] ) ;
73
+ arr [ i ] = new RowBoundPropertyDescriptor ( type , names [ i ] , i ) ;
74
74
}
75
75
return new PropertyDescriptorCollection ( arr , true ) ;
76
76
}
@@ -84,20 +84,22 @@ internal static PropertyDescriptorCollection GetProperties(DapperTable table, ID
84
84
private sealed class RowBoundPropertyDescriptor : PropertyDescriptor
85
85
{
86
86
private readonly Type _type ;
87
- public RowBoundPropertyDescriptor ( Type type , string name ) : base ( name , null )
88
- => _type = type ;
89
-
90
- public override bool CanResetValue ( object component ) => false ;
91
- public override void ResetValue ( object component ) => throw new NotSupportedException ( ) ;
92
-
87
+ private readonly int _index ;
88
+ public RowBoundPropertyDescriptor ( Type type , string name , int index ) : base ( name , null )
89
+ {
90
+ _type = type ;
91
+ _index = index ;
92
+ }
93
+ public override bool CanResetValue ( object component ) => true ;
94
+ public override void ResetValue ( object component ) => ( ( DapperRow ) component ) . Remove ( _index ) ;
93
95
public override bool IsReadOnly => false ;
94
- public override bool ShouldSerializeValue ( object component ) => true ;
96
+ public override bool ShouldSerializeValue ( object component ) => ( ( DapperRow ) component ) . TryGetValue ( _index , out _ ) ;
95
97
public override Type ComponentType => typeof ( DapperRow ) ;
96
98
public override Type PropertyType => _type ;
97
99
public override object GetValue ( object component )
98
- => ( ( IDictionary < string , object > ) component ) . TryGetValue ( Name , out var val ) ? val : null ;
100
+ => ( ( DapperRow ) component ) . TryGetValue ( _index , out var val ) ? ( val ?? DBNull . Value ) : DBNull . Value ;
99
101
public override void SetValue ( object component , object value )
100
- => ( ( IDictionary < string , object > ) component ) [ Name ] = value ;
102
+ => ( ( DapperRow ) component ) . SetValue ( _index , value is DBNull ? null : value ) ;
101
103
}
102
104
}
103
105
}
0 commit comments