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

Refactor to eliminate repetitive code. #783

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Oqtane.Client/Services/ServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,15 @@ public string CreateApiUrl(Alias alias, string serviceName)
// add entityid parameter to url for custom authorization policy
public string CreateAuthorizationPolicyUrl(string url, int entityId)
{
string qs = "entityid=" + entityId.ToString();
Copy link
Contributor

Choose a reason for hiding this comment

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

What about

return url.Contains("?") ? "&" : "?" + "entityid=" + entityId.ToString(); 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I go for the simple approach. I know what the code you pasted does, but IMO it's so complex for a one-liner.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not that complex ;) coz the first letter depends on whether the url contains query string or not

Copy link
Contributor

Choose a reason for hiding this comment

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

Both ways are fine for me. The boss indicated a preference for the longer form.
#155 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer inline condition in such case but if the condition is complex or has nested conditions I may prefer if block for readability

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @jimspillane I thought I had read that somewhere. Plus at this point I don't want to change a lot of the code, meaning if it's an 'if block', then I will leave it as an if block.

Copy link
Contributor

Choose a reason for hiding this comment

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

This take too long for a tiny change ;) could you please give a meaningful name instead of qs and I'm fine with that


if (url.Contains("?"))
{
return url + "&entityid=" + entityId.ToString();
return url + "&" + qs;
}
else
{
return url + "?entityid=" + entityId.ToString();
return url + "?" + qs;
}
}

Expand Down