Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 02ff1d2

Browse files
committed
Update UpdateFilter/InsertFilter example
1 parent 85bec23 commit 02ff1d2

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,14 +1992,12 @@ public interface IAudit
19921992
}
19931993

19941994
OrmLiteConfig.InsertFilter = (dbCmd, row) => {
1995-
var auditRow = row as IAudit;
1996-
if (auditRow != null)
1995+
if (row is IAudit auditRow)
19971996
auditRow.CreatedDate = auditRow.ModifiedDate = DateTime.UtcNow;
19981997
};
19991998

20001999
OrmLiteConfig.UpdateFilter = (dbCmd, row) => {
2001-
var auditRow = row as IAudit;
2002-
if (auditRow != null)
2000+
if (row is IAudit auditRow)
20032001
auditRow.ModifiedDate = DateTime.UtcNow;
20042002
};
20052003
```
@@ -2012,8 +2010,7 @@ The filters can also be used for validation where throwing an exception will pre
20122010

20132011
```csharp
20142012
OrmLiteConfig.InsertFilter = OrmLiteConfig.UpdateFilter = (dbCmd, row) => {
2015-
var auditRow = row as IAudit;
2016-
if (auditRow != null && auditRow.ModifiedBy == null)
2013+
if (row is IAudit auditRow && auditRow.ModifiedBy == null)
20172014
throw new ArgumentNullException("ModifiedBy");
20182015
};
20192016

tests/ServiceStack.OrmLite.Tests/OrmLiteFiltersTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,15 @@ public void Does_call_Filters_on_Save()
9797

9898
OrmLiteConfig.InsertFilter = (dbCmd, row) =>
9999
{
100-
var auditRow = row as IAudit;
101-
if (auditRow != null)
100+
if (row is IAudit auditRow)
102101
{
103102
auditRow.CreatedDate = auditRow.ModifiedDate = insertDate;
104103
}
105104
};
106105

107106
OrmLiteConfig.UpdateFilter = (dbCmd, row) =>
108107
{
109-
var auditRow = row as IAudit;
110-
if (auditRow != null)
108+
if (row is IAudit auditRow)
111109
{
112110
auditRow.ModifiedDate = updateDate;
113111
}
@@ -147,8 +145,7 @@ public void Exceptions_in_filters_prevents_insert_and_update()
147145
{
148146
OrmLiteConfig.InsertFilter = OrmLiteConfig.UpdateFilter = (dbCmd, row) =>
149147
{
150-
var auditRow = row as IAudit;
151-
if (auditRow != null)
148+
if (row is IAudit auditRow)
152149
{
153150
if (auditRow.ModifiedBy == null)
154151
throw new ArgumentNullException("ModifiedBy");

0 commit comments

Comments
 (0)