Add string+PathString operator to prevent too much string<->PathString implicit conversion.

This commit is contained in:
Chris Ross 2015-04-21 10:23:22 -07:00
parent 0737ea392f
commit 86bd393d3d
2 changed files with 26 additions and 0 deletions

View File

@ -215,6 +215,18 @@ namespace Microsoft.AspNet.Http
return !left.Equals(right, StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// </summary>
/// <param name="left">The left parameter</param>
/// <param name="right">The right parameter</param>
/// <returns>The ToString combination of both values</returns>
public static string operator +(string left, PathString right)
{
// This overload exists to prevent the implicit string<->PathString converter from
// trying to call the PathString+PathString operator for things that are not path strings.
return string.Concat(left, right.ToString());
}
/// <summary>
/// Operator call through to Add
/// </summary>

View File

@ -50,5 +50,19 @@ namespace Microsoft.AspNet.Http
// Assert
Assert.Equal(expected, result.Value);
}
[Fact]
public void ImplicitStringConverters_WorksWithAdd()
{
var scheme = "http";
var host = new HostString("localhost:80");
var pathBase = new PathString("/base");
var path = new PathString("/path");
var query = new QueryString("?query");
var fragment = new FragmentString("#frag");
var result = scheme + "://" + host + pathBase + path + query + fragment;
Assert.Equal("http://localhost:80/base/path?query#frag", result);
}
}
}