Skip to content

Commit

Permalink
Handle DBNull's.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Jul 7, 2011
1 parent 01daae3 commit 8dd0c2a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions mcs/class/WebMatrix.Data/WebMatrix.Data/DynamicRecord.cs
Expand Up @@ -52,13 +52,23 @@ internal DynamicRecord (Dictionary<string, object> fields)

public object this[string name] {
get {
return fields[name];
var retval = fields[name];

if (retval == DBNull.Value)
return null;

return retval;
}
}

public object this[int index] {
get {
return fields[Columns[index]];
var retval = fields[Columns[index]];

if (retval == DBNull.Value)
return null;

return retval;
}
}

Expand All @@ -69,7 +79,12 @@ public override IEnumerable<string> GetDynamicMemberNames ()

public override bool TryGetMember (GetMemberBinder binder, out object result)
{
return fields.TryGetValue (binder.Name, out result);
bool success = fields.TryGetValue (binder.Name, out result);

if (result == DBNull.Value)
result = null;

return success;
}

AttributeCollection ICustomTypeDescriptor.GetAttributes ()
Expand Down

0 comments on commit 8dd0c2a

Please sign in to comment.