Skip to content

Support setting parameters with a dynamic object #2320

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

Conversation

fredericDelaporte
Copy link
Member

Fixes #2009

@fredericDelaporte fredericDelaporte added this to the 5.3 milestone Mar 1, 2020
@fredericDelaporte fredericDelaporte force-pushed the SetParametersFromDictionary branch from 3017c72 to 097aad5 Compare March 1, 2020 20:27
@@ -651,6 +651,8 @@ public IQuery SetEnum(string name, Enum val)
return this;
}

// Since 5.3
[Obsolete("This method was never surfaced to a query interface. Use the overload or extension method taking a generic dictionary instead.")]
public IQuery SetProperties(IDictionary map)
Copy link
Member Author

Choose a reason for hiding this comment

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

I have considered adding an extension method for it too, but this was causing an ambiguous method call when using a Dictionary<string, object>, since it does implement both IDictionary and IDictionary<string, object>. So it looks to me not worth keeping this method.

/// </summary>
/// <param name="query">The query on which to set the parameters.</param>
/// <param name="map">A dictionary of parameters values by names.</param>
public static IQuery SetParameters(this IQuery query, IDictionary<string, object> map)
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to change the name, since non extension methods takes precedence. Moreover the name SetProperties does not make much sense in my view, this one is more semantically accurate I think.

So I have added a commit to obsolete SetProperties in favor of a SetParameters overload.

}

// Since 5.3
[Obsolete("Use SetParameters method instead.")]
public IQuery SetProperties(object bean)
Copy link
Member

Choose a reason for hiding this comment

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

What if we use this method to support the IDictionary<string, object>?

Suggested change
public IQuery SetProperties(object bean)
public IQuery SetProperties(object bean)
{
if (bean is IDictionary<string, object> map)
{
// TODO:
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be less discoverable, but it would support dynamic without having to do an explicit static call on some extension class.

@fredericDelaporte fredericDelaporte deleted the SetParametersFromDictionary branch March 29, 2020 14:39
@fredericDelaporte fredericDelaporte removed this from the 5.3 milestone Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for IDictionary<string, object> to IQuery.SetProperties
2 participants