本文整理汇总了C#中Uri.GetComponents方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.GetComponents方法的具体用法?C# Uri.GetComponents怎么用?C# Uri.GetComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uri
的用法示例。
在下文中一共展示了Uri.GetComponents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetComponents_PunycodeHostIriOnIdnOff_LowerCaseResult
public void GetComponents_PunycodeHostIriOnIdnOff_LowerCaseResult()
{
Uri testUri = new Uri("http://wWw.xn--pCk.Com");
Assert.Equal("www.xn--pck.com", testUri.GetComponents(UriComponents.Host, UriFormat.UriEscaped));
Assert.Equal("www.xn--pck.com", testUri.Host);
Assert.Equal("www.xn--pck.com", testUri.DnsSafeHost);
}
示例2: GetNameFromAtomLinkRelationAttribute
internal static string GetNameFromAtomLinkRelationAttribute(string value)
{
string name = null;
if (!String.IsNullOrEmpty(value))
{
Uri uri = null;
try
{
uri = new Uri(value, UriKind.RelativeOrAbsolute);
}
catch (UriFormatException)
{ }
if ((null != uri) && uri.IsAbsoluteUri)
{
string unescaped = uri.GetComponents(UriComponents.AbsoluteUri, UriFormat.SafeUnescaped);
if (unescaped.StartsWith(XmlConstants.DataWebRelatedNamespace, StringComparison.Ordinal))
{
name = unescaped.Substring(XmlConstants.DataWebRelatedNamespace.Length);
}
}
}
return name;
}
示例3: GetFilepath
private bool GetFilepath(string inUrl, out string cleanUrl)
{
var asUri = new Uri(inUrl);
cleanUrl = asUri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
bool isFile = (asUri.Scheme == "file" || asUri.Host.ToLower() != m_ResourcesHost);
return isFile;
}
示例4: Parse
public virtual ODataPath Parse(Uri uri, Uri baseUri)
{
if (uri == null)
{
throw Error.ArgumentNull("uri");
}
if (baseUri == null)
{
throw Error.ArgumentNull("baseUri");
}
string uriPath = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
string basePath = baseUri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
if (!uriPath.StartsWith(basePath, StringComparison.OrdinalIgnoreCase))
{
return null;
}
string relativePath = uriPath.Substring(basePath.Length);
ODataPath path = new ODataPath();
ODataPathSegment pathSegment = new ServiceBasePathSegment(baseUri);
path.Segments.AddLast(pathSegment);
foreach (string segment in ParseSegments(relativePath))
{
pathSegment = ParseNextSegment(pathSegment, segment);
// If the Uri stops matching the model at any point, return null
if (pathSegment == null)
{
return null;
}
path.Segments.AddLast(pathSegment);
}
return path;
}
示例5: WriteUri
internal void WriteUri(Uri value)
{
writer.WriteString(value.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped));
}
示例6: TestGetComponentParts
public static void TestGetComponentParts()
{
Uri uri = new Uri("http://www.contoso.com/path?name#frag");
String s;
s = uri.GetComponents(UriComponents.Fragment, UriFormat.UriEscaped);
Assert.Equal(s, "frag");
s = uri.GetComponents(UriComponents.Host, UriFormat.UriEscaped);
Assert.Equal(s, "www.contoso.com");
}
示例7: TestParseUserPath
public static void TestParseUserPath()
{
var u = new Uri("https://a.net/[email protected]");
var result = u.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.UriEscaped);
Assert.Equal(result, "https://a.net/[email protected]");
}
示例8: IsBaseOf
internal bool IsBaseOf(Uri fullAddress)
{
if ((object)_baseAddress.Scheme != (object)fullAddress.Scheme)
{
return false;
}
if (_baseAddress.Port != fullAddress.Port)
{
return false;
}
if (this.HostNameComparisonMode == HostNameComparisonMode.Exact)
{
if (string.Compare(_baseAddress.Host, fullAddress.Host, StringComparison.OrdinalIgnoreCase) != 0)
{
return false;
}
}
string s1 = _baseAddress.GetComponents(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.Unescaped);
string s2 = fullAddress.GetComponents(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.Unescaped);
if (s1.Length > s2.Length)
{
return false;
}
if (s1.Length < s2.Length &&
s1[s1.Length - 1] != segmentDelimiter &&
s2[s1.Length] != segmentDelimiter)
{
// Matching over segments
return false;
}
return string.Compare(s2, 0, s1, 0, s1.Length, StringComparison.OrdinalIgnoreCase) == 0;
}
示例9: Main
static int Main(string[] args)
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
string filename;
string prefix = "";
Uri uri;
int count = 0;
int choice = -1;
Console.Out.NewLine="\n";
Console.Error.NewLine="\n";
if (args.Length >= 1) {
//choice = Int32.ParseInt(args[0]);
if (!Int32.TryParse(args[0], out choice)) {
Console.Error.WriteLine("Error! argument could not be parsed.");
choice = -1;
return 1;
}
}
foreach ( SHDocVw.InternetExplorer ie in shellWindows )
{
filename = Path.GetFileNameWithoutExtension( ie.FullName ).ToLower();
/*
if ( filename.Equals( "iexplore" ) ) {
Console.WriteLine( "Web Site : {0} == {1}", ie.LocationURL, ie.LocationName);
}
*/
if ( filename.Equals( "explorer" ) && ie.LocationURL.StartsWith( "file://" )) {
if (choice > -1) {
if (choice == count) {
prefix = "";
} else if (count < choice) {
count++;
continue;
} else {
break;
}
} else {
prefix = count + ": ";
}
///Console.WriteLine("after choice check");
if (ie.LocationURL.StartsWith("file:///")) {
uri = new Uri(ie.LocationURL);
Console.WriteLine( "{0}{1}", prefix, uri.GetComponents(UriComponents.Path, UriFormat.Unescaped));
} else {
uri = new Uri(ie.LocationURL);
Console.WriteLine( "{0}//{1}", prefix,
uri.GetComponents(UriComponents.Path | UriComponents.Host, UriFormat.Unescaped));
}
count++;
}
}
if (choice > -1 && choice >= count) {
Console.Error.WriteLine("Error! argument too large");
return 1;
}
return 0;
}
示例10: GetComponents_Invalid
public void GetComponents_Invalid()
{
var absoluteUri = new Uri("http://domain");
var relativeUri = new Uri("path", UriKind.Relative);
Assert.Throws<ArgumentOutOfRangeException>(() => absoluteUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped - 1)); // Format is invalid
Assert.Throws<ArgumentOutOfRangeException>(() => absoluteUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.SafeUnescaped + 1)); // Format is invalid
Assert.Throws<ArgumentOutOfRangeException>("components", () => absoluteUri.GetComponents(UriComponents.HostAndPort | ~UriComponents.KeepDelimiter, UriFormat.UriEscaped)); // Components is invalid
Assert.Throws<InvalidOperationException>(() => relativeUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.Unescaped)); // Uri is relative
Assert.Throws<ArgumentOutOfRangeException>(() => relativeUri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped - 1)); // Uri is relative, format is invalid
Assert.Throws<ArgumentOutOfRangeException>(() => relativeUri.GetComponents(UriComponents.SerializationInfoString, UriFormat.SafeUnescaped + 1)); // Uri is relative, format is invalid
}
示例11: GetComponents
public void GetComponents(Uri uri, UriComponents components, UriFormat format, string expected)
{
Assert.Equal(expected, uri.GetComponents(components, format));
}
示例12: UriMailTo_EAI_SomeEscaping
public void UriMailTo_EAI_SomeEscaping()
{
Uri uri = new Uri("mailto:\[email protected]\u30AF");
Assert.Equal("mailto", uri.Scheme);
Assert.Equal("mailto:%E3%82%[email protected]\u30AF", uri.AbsoluteUri);
Assert.Equal("mailto:\[email protected]\u30AF", uri.ToString());
Assert.Equal("%E3%82%AF", uri.UserInfo);
Assert.Equal("\u30AF", uri.Host);
Assert.Equal("", uri.AbsolutePath);
Assert.Equal("\[email protected]\u30AF", uri.GetComponents(UriComponents.UserInfo | UriComponents.Host, UriFormat.SafeUnescaped));
}
示例13: Compare
public static int Compare(Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat)
{
if ((uri1 == null) && (uri2 == null))
return 0;
if (uri1 == null)
return -1;
if (uri2 == null)
return 1;
string s1 = uri1.GetComponents(partsToCompare, compareFormat);
string s2 = uri2.GetComponents(partsToCompare, compareFormat);
return String.Compare(s1.ToLower(), s2.ToLower());
}
示例14: GetCanonicalKey
//
// We want to serialize on updates on one thread.
//
private static string GetCanonicalKey(string key)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
try
{
Uri uri = new Uri(key);
key = uri.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped);
}
catch (UriFormatException e)
{
throw new ArgumentException(SR.Format(SR.net_mustbeuri, "key"), "key", e);
}
return key;
}
示例15: GetPathInfo
/// <summary>
/// <para>Gets the path component of the Uri</para>
/// </summary>
private static void GetPathInfo(GetPathOption pathOption,
Uri uri,
out string path,
out string directory,
out string filename)
{
path = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
int index = path.LastIndexOf('/');
if (pathOption == GetPathOption.AssumeFilename &&
index != -1 && index == path.Length - 1)
{
// Remove last '/' and continue normal processing
path = path.Substring(0, path.Length - 1);
index = path.LastIndexOf('/');
}
// split path into directory and filename
if (pathOption == GetPathOption.AssumeNoFilename)
{
directory = path;
filename = string.Empty;
}
else
{
directory = path.Substring(0, index + 1);
filename = path.Substring(index + 1, path.Length - (index + 1));
}
// strip off trailing '/' on directory if present
if (directory.Length > 1 && directory[directory.Length - 1] == '/')
directory = directory.Substring(0, directory.Length - 1);
}