本文整理汇总了C#中Uri.ParseQueryString方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.ParseQueryString方法的具体用法?C# Uri.ParseQueryString怎么用?C# Uri.ParseQueryString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uri
的用法示例。
在下文中一共展示了Uri.ParseQueryString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseQueryStringSucceeds
public void ParseQueryStringSucceeds(Uri address)
{
NameValueCollection result = address.ParseQueryString();
Assert.NotNull(result);
bool addressContainsQuery = address.Query.Contains("?");
if (!addressContainsQuery)
{
Assert.Empty(result);
}
else
{
Assert.True(result.Count > 0, "Uri with query string should return non-empty set.");
}
}
示例2: Parse
private static ODataPath Parse(
IEdmModel model,
string serviceRoot,
string odataPath,
ODataUriResolverSetttings resolverSettings,
bool enableUriTemplateParsing)
{
ODataUriParser uriParser;
Uri serviceRootUri = null;
Uri fullUri = null;
NameValueCollection queryString = null;
if (enableUriTemplateParsing)
{
uriParser = new ODataUriParser(model, new Uri(odataPath, UriKind.Relative));
uriParser.EnableUriTemplateParsing = true;
}
else
{
Contract.Assert(serviceRoot != null);
serviceRootUri = new Uri(
serviceRoot.EndsWith("/", StringComparison.Ordinal) ?
serviceRoot :
serviceRoot + "/");
fullUri = new Uri(serviceRootUri, odataPath);
queryString = fullUri.ParseQueryString();
uriParser = new ODataUriParser(model, serviceRootUri, fullUri);
}
uriParser.UrlConventions = resolverSettings.UrlConventions;
uriParser.Resolver = resolverSettings.CreateResolver(model);
Semantic.ODataPath path;
UnresolvedPathSegment unresolvedPathSegment = null;
Semantic.KeySegment id = null;
try
{
path = uriParser.ParsePath();
}
catch (ODataUnrecognizedPathException ex)
{
if (ex.ParsedSegments != null &&
ex.ParsedSegments.Count() > 0 &&
(ex.ParsedSegments.Last().EdmType is IEdmComplexType ||
ex.ParsedSegments.Last().EdmType is IEdmEntityType) &&
ex.CurrentSegment != ODataSegmentKinds.Count)
{
if (ex.UnparsedSegments.Count() == 0)
{
path = new Semantic.ODataPath(ex.ParsedSegments);
unresolvedPathSegment = new UnresolvedPathSegment(ex.CurrentSegment);
}
else
{
// Throw ODataException if there is some segment following the unresolved segment.
throw new ODataException(Error.Format(
SRResources.InvalidPathSegment,
ex.UnparsedSegments.First(),
ex.CurrentSegment));
}
}
else
{
throw;
}
}
if (!enableUriTemplateParsing && path.LastSegment is Semantic.NavigationPropertyLinkSegment)
{
IEdmCollectionType lastSegmentEdmType = path.LastSegment.EdmType as IEdmCollectionType;
if (lastSegmentEdmType != null)
{
Semantic.EntityIdSegment entityIdSegment = null;
bool exceptionThrown = false;
try
{
entityIdSegment = uriParser.ParseEntityId();
if (entityIdSegment != null)
{
// Create another ODataUriParser to parse $id, which is absolute or relative.
ODataUriParser parser = new ODataUriParser(model, serviceRootUri, entityIdSegment.Id);
id = parser.ParsePath().LastSegment as Semantic.KeySegment;
}
}
catch (ODataException)
{
// Exception was thrown while parsing the $id.
// We will throw another exception about the invalid $id.
exceptionThrown = true;
}
if (exceptionThrown ||
(entityIdSegment != null &&
(id == null ||
//.........这里部分代码省略.........
示例3: QueryString_DelegatesToHttpRequestMessage
public void QueryString_DelegatesToHttpRequestMessage(string requestUri)
{
// Arrange
Uri reqUri = new Uri(requestUri);
NameValueCollection expectedQueryString = reqUri.ParseQueryString();
HttpRequestMessage request = new HttpRequestMessage
{
RequestUri = reqUri
};
HttpRequestMessageWrapper wrapper = new HttpRequestMessageWrapper("/", request);
// Act
NameValueCollection actualQuery = wrapper.QueryString;
// Assert
Assert.Equal(expectedQueryString.ToString(), actualQuery.ToString());
}