Commit 07bc83f2 authored by mgravell's avatar mgravell

tidy ReadChar/ReadNullableChar with modern C#

parent a47f23cc
......@@ -1876,13 +1876,8 @@ private static Exception MultiMapException(IDataRecord reader)
public static char ReadChar(object value)
{
if (value == null || value is DBNull) throw new ArgumentNullException(nameof(value));
var s = value as string;
if (s == null)
{
var c = value as char?;
if (c != null) return c.Value;
}
else if (s.Length == 1) return s[0];
if (value is string s && s.Length == 1) return s[0];
if (value is char c) return c;
throw new ArgumentException("A single-character was expected", nameof(value));
}
......@@ -1896,13 +1891,8 @@ public static char ReadChar(object value)
public static char? ReadNullableChar(object value)
{
if (value == null || value is DBNull) return null;
var s = value as string;
if (s == null)
{
var c = value as char?;
if (c != null) return c;
}
else if (s.Length == 1) return s[0];
if (value is string s && s.Length == 1) return s[0];
if (value is char c) return c;
throw new ArgumentException("A single-character was expected", nameof(value));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment