Commit 1df754e3 authored by Sam Saffron's avatar Sam Saffron

reduce lines of code

parent aacfdf25
...@@ -404,35 +404,24 @@ private static CacheInfo GetCacheInfo(object param, Identity identity) ...@@ -404,35 +404,24 @@ private static CacheInfo GetCacheInfo(object param, Identity identity)
private static object GetDynamicDeserializer(IDataRecord reader, int startBound = 0, int length = -1, bool returnNullIfFirstMissing = false) private static object GetDynamicDeserializer(IDataRecord reader, int startBound = 0, int length = -1, bool returnNullIfFirstMissing = false)
{ {
var colNames = new List<string>();
if (length == -1) if (length == -1)
{ {
length = reader.FieldCount - startBound; length = reader.FieldCount - startBound;
} }
for (var i = startBound; i < startBound + length; i++)
{
colNames.Add(reader.GetName(i));
}
Func<IDataReader, ExpandoObject> rval = Func<IDataReader, ExpandoObject> rval =
r => r =>
{ {
IDictionary<string, object> row = new ExpandoObject(); IDictionary<string, object> row = new ExpandoObject();
var i = startBound; for (var i = startBound; i < startBound + length; i++)
var first = true;
foreach (var colName in colNames)
{ {
var tmp = r.GetValue(i); var tmp = r.GetValue(i);
tmp = tmp == DBNull.Value ? null : tmp; tmp = tmp == DBNull.Value ? null : tmp;
row[colName] = tmp; row[r.GetName(i)] = tmp;
if (returnNullIfFirstMissing && first && tmp == null) if (returnNullIfFirstMissing && i == startBound && tmp == null)
{ {
return null; return null;
} }
i++;
first = false;
} }
return (ExpandoObject)row; return (ExpandoObject)row;
}; };
......
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