# Method for get base URI

How can I improve the following code?

private const string OAuthTokenUri = "oauth2/token";

{
var baseUri = uri.GetLeftPart(UriPartial.Authority);
var s = new Uri(new Uri(baseUri), OAuthTokenUri);
return s.ToString();
}


I call GetOAuthTokenUri() like:

var oauthTokenUri = GetOAuthTokenUri("http://www.example.com/mypage/default.aspx");


As a result I'm getting

http://www.example.com/oauth2/token


Please help to improve GetOAuthTokenUri

• So what's your issue? Isn't it working like you expect it to? – BCdotWEB Mar 9 '16 at 11:59
• All works but I want to improve it. This is CodeReview, just for review but not for fix bugs – Roman Marusyk Mar 9 '16 at 12:00
• I don't really see the point of posting a fairly short method and asking for improvements. I'd say that s is a bad variable name and I don't see the point of assigning it (can't you return new Uri(new Uri(baseUri), OAuthTokenUri).ToString());), but there's not much of substance here to warrant a review. – BCdotWEB Mar 9 '16 at 12:12

Maybe you can do it like this:

private const string OAuthTokenUri = "/oauth2/token";


• Why return string.Empty? Why even use Uri.TryCreate to avoid throwing an exception? – BCdotWEB Mar 9 '16 at 12:16
• Because now you need to check whether you get back null or even worse string.Empty. IMHO this is a case where I'd want to get an exception to be thrown. – BCdotWEB Mar 9 '16 at 13:34