Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DapperRow implement IReadOnlyDictionary<string, object> #913

Merged
merged 1 commit into from
Mar 7, 2018

Conversation

marcelltoth
Copy link
Contributor

.NET 4.5 Introduced IReadOnlyDictionary<string, object> which is kind of a subset of IDictionary<string, object>. This interface is really useful especially in immutable object models. However, for legacy reasons IDictionary does not inherit from IReadOnlyDictionary unfortunately.

This pull request makes the internal DapperRow class implement IReadOnlyDictionary<string, object> so we can simply pass a row into an API taking that kind of parameter, without the performance penalty of copying the row into a new Dictionary.


IEnumerable<string> IReadOnlyDictionary<string, object>.Keys
{
get { return this.Select(kv => kv.Key); }
Copy link
Member

@mgravell mgravell Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly return table.FieldNames; ? although this would expose the field-names to abuse... slightly probematic; oh, and this array might be over-sized? hmmm, probably just ignore me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: yeah, this (my code, not yours) also wouldn't take dead values into account; probably best to leave it alone

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea. I pretty much copied this from the existing IDictionary implementation, however so it really might be best to leave alone, for the sake of consistency.
(The only difference in the implementation is me skipping the .ToArray() at the end because for this interface it is enough to return an IEnumerable)


IEnumerable<object> IReadOnlyDictionary<string, object>.Values
{
get { return this.Select(kv => kv.Value); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly return values;, although similar concerns to Keys - probably best to leave this "as is", too!

@NickCraver NickCraver merged commit 671419c into DapperLib:master Mar 7, 2018
@NickCraver
Copy link
Member

Merging in :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants