Skip to content

Commit 07bc83f

Browse files
committed
tidy ReadChar/ReadNullableChar with modern C#
1 parent a47f23c commit 07bc83f

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

Dapper/SqlMapper.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,13 +1876,8 @@ internal static Func<IDataReader, object> GetDapperRowDeserializer(IDataRecord r
18761876
public static char ReadChar(object value)
18771877
{
18781878
if (value == null || value is DBNull) throw new ArgumentNullException(nameof(value));
1879-
var s = value as string;
1880-
if (s == null)
1881-
{
1882-
var c = value as char?;
1883-
if (c != null) return c.Value;
1884-
}
1885-
else if (s.Length == 1) return s[0];
1879+
if (value is string s && s.Length == 1) return s[0];
1880+
if (value is char c) return c;
18861881
throw new ArgumentException("A single-character was expected", nameof(value));
18871882
}
18881883

@@ -1896,13 +1891,8 @@ public static char ReadChar(object value)
18961891
public static char? ReadNullableChar(object value)
18971892
{
18981893
if (value == null || value is DBNull) return null;
1899-
var s = value as string;
1900-
if (s == null)
1901-
{
1902-
var c = value as char?;
1903-
if (c != null) return c;
1904-
}
1905-
else if (s.Length == 1) return s[0];
1894+
if (value is string s && s.Length == 1) return s[0];
1895+
if (value is char c) return c;
19061896
throw new ArgumentException("A single-character was expected", nameof(value));
19071897
}
19081898

0 commit comments

Comments
 (0)