本文整理汇总了C#中System.Uri.AppendParameter方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.AppendParameter方法的具体用法?C# Uri.AppendParameter怎么用?C# Uri.AppendParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.AppendParameter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendParameterSuccessEmptyQuery
public void AppendParameterSuccessEmptyQuery()
{
Uri url = new Uri(BaseUrl);
const string key = "Test";
const string value = "InsertedValue";
string appendedUrl = url.AppendParameter(key, value);
Assert.AreEqual($"{BaseUrl}?{key}={value}",appendedUrl);
}
示例2: AppendParameterEmptyKey
public void AppendParameterEmptyKey()
{
string key = string.Empty;
const string value = "InsertedValue";
string extendedBaseUrl = $"{BaseUrl}";
Uri url = new Uri(extendedBaseUrl);
string appendedUrl = url.AppendParameter(key, value);
Assert.AreEqual(url.AbsoluteUri, appendedUrl);
}
示例3: AppendParameterSuccessBaseUrlWithExistingKey
public void AppendParameterSuccessBaseUrlWithExistingKey()
{
const string key = "Test";
const string value = "InsertedValue";
string extendedBaseUrl = $"{BaseUrl}?{key}=PreValue";
Uri url = new Uri(extendedBaseUrl);
string appendedUrl = url.AppendParameter(key, value);
Assert.AreEqual($"{BaseUrl}?{key}={value}", appendedUrl);
}
示例4: AppendParameterSuccessBaseUrlWithSubPageAndQuery
public void AppendParameterSuccessBaseUrlWithSubPageAndQuery()
{
string extendedBaseUrl = $"{BaseUrl}/SubPage?ExtendedParam=Value";
Uri url = new Uri(extendedBaseUrl);
const string key = "Test";
const string value = "InsertedValue";
string appendedUrl = url.AppendParameter(key, value);
Assert.AreEqual($"{extendedBaseUrl}&{key}={value}", appendedUrl);
}
示例5: GeneratePaging
/// <summary>
/// Generates a List of Paging Elements based on the parameter
/// </summary>
/// <returns>List of Paging elements, without previous and next</returns>
public PagingModel GeneratePaging(Uri url, int pageNumber, int totalNumberOfElements)
{
int lastElement = (totalNumberOfElements / Settings.ElementsPerPage) + 1;
return new PagingModel()
{
Elements = GeneratePagingElements(url, pageNumber, totalNumberOfElements),
Last = new PageElement()
{
IsActive = false,
Text = Labels.NextPagingElementText,
Url = url.AppendParameter(Labels.PagingKey, lastElement.ToString())
},
First = new PageElement()
{
IsActive = false,
Text = Labels.PreviousPagingElementText,
Url = url.AppendParameter(Labels.PagingKey, "1")
}
};
}
示例6: GeneratePagingElements
/// <summary>
/// Helper to generate a specific paging element with the given parameters
/// </summary>
/// <param name="url">url</param>
/// <param name="pageNumber">page number</param>
/// <param name="totalNumberOfElements">total number of elements</param>
/// <returns>a filled paging element</returns>
private static IEnumerable<PageElement> GeneratePagingElements(Uri url, int pageNumber, int totalNumberOfElements)
{
// Prepare the limits for the Paging elements
int numberOfPagingElements = Settings.NumberOfPaingElements;
int startIndex = pageNumber - numberOfPagingElements > 1 ? pageNumber - numberOfPagingElements : 1;
int endIndex = pageNumber + numberOfPagingElements <= ((totalNumberOfElements / Settings.ElementsPerPage) + 1)
? pageNumber + numberOfPagingElements
: (totalNumberOfElements / Settings.ElementsPerPage) + 1;
// Use the limits for building the Paging
for (int index = startIndex; index <= endIndex; index++)
{
string newUrl = url.AppendParameter(Labels.PagingKey, index.ToString());
yield return new PageElement()
{
Text = index.ToString(),
Url = newUrl,
IsActive = pageNumber == index
};
}
}
示例7: AppendParameterNullValue
public void AppendParameterNullValue()
{
const string key = "Test";
string value = null;
string extendedBaseUrl = $"{BaseUrl}";
Uri url = new Uri(extendedBaseUrl);
string appendedUrl = url.AppendParameter(key, value);
Assert.AreEqual(url.AbsoluteUri, appendedUrl);
}