4
4
using System . Linq ;
5
5
using System . Threading . Tasks ;
6
6
using TabBlazor . Components . Tables ;
7
+ using TabBlazor ;
7
8
using LinqKit ;
8
9
9
10
namespace TabBlazor
@@ -36,9 +37,9 @@ public string Title
36
37
[ Parameter ] public Expression < Func < Item , object > > Property { get ; set ; }
37
38
[ Parameter ] public Expression < Func < Item , string , bool > > SearchExpression { get ; set ; }
38
39
[ Parameter ] public SortOrder ? Sort { get ; set ; }
39
- [ Parameter ] public Align Align { get ; set ; }
40
- [ Parameter ] public bool Group { get ; set ; }
41
-
40
+ [ Parameter ] public Align Align { get ; set ; }
41
+ [ Parameter ] public bool Group { get ; set ; }
42
+
42
43
public bool SortColumn { get ; set ; }
43
44
public bool GroupBy { get ; set ; }
44
45
public bool SortDescending { get ; set ; }
@@ -76,7 +77,23 @@ protected override void OnParametersSet()
76
77
}
77
78
78
79
Type = Property ? . GetPropertyMemberInfo ( ) . GetMemberUnderlyingType ( ) ;
79
- }
80
+
81
+ PropertyNullSafe = ( Expression < Func < Item , object > > ) Property ? . PropagateNull ( ) ;
82
+
83
+ }
84
+
85
+ public Expression < Func < Item , object > > PropertyNullSafe { get ; private set ; }
86
+
87
+ //private Expression<Func<Item, object>> propertyNullSafe;
88
+ //public Expression<Func<Item, object>> PropertyNullSafe
89
+ //{
90
+ // get
91
+ // {
92
+ // if (Property == null) { return null; }
93
+ // propertyNullSafe ??= (Expression<Func<Item, object>>)Property.PropagateNull();
94
+ // return propertyNullSafe;
95
+ // }
96
+ //}
80
97
81
98
public Expression < Func < Item , bool > > GetFilter ( ITableState < Item > state )
82
99
{
@@ -100,8 +117,8 @@ public Expression<Func<Item, bool>> GetFilter(ITableState<Item> state)
100
117
private Expression < Func < Item , bool > > NotNull ( )
101
118
{
102
119
return Expression . Lambda < Func < Item , bool > > (
103
- Expression . NotEqual ( Property . Body , Expression . Constant ( null ) ) ,
104
- Property . Parameters . ToArray ( )
120
+ Expression . NotEqual ( PropertyNullSafe . Body , Expression . Constant ( null ) ) ,
121
+ PropertyNullSafe . Parameters . ToArray ( )
105
122
) ;
106
123
}
107
124
@@ -139,12 +156,12 @@ public async Task SortByAsync()
139
156
if ( SortDescending && Table . ResetSortCycle )
140
157
{
141
158
sortOnColumn = false ;
142
- }
143
- SortDescending = ! SortDescending ;
159
+ }
160
+ SortDescending = ! SortDescending ;
144
161
}
145
162
146
- Table . Columns . ForEach ( x => x . SortColumn = false ) ;
147
-
163
+ Table . Columns . ForEach ( x => x . SortColumn = false ) ;
164
+
148
165
SortColumn = sortOnColumn ;
149
166
await Table . Update ( ) ;
150
167
}
@@ -153,8 +170,9 @@ public async Task SortByAsync()
153
170
public object GetValue ( Item item )
154
171
{
155
172
try
156
- {
157
- return Property . Compile ( ) . Invoke ( item ) ;
173
+ {
174
+ return PropertyNullSafe . Compile ( ) . Invoke ( item ) ;
175
+ // return Property.Compile().Invoke(item);
158
176
}
159
177
catch ( NullReferenceException )
160
178
{
0 commit comments