当前位置: 首页>>代码示例>>C#>>正文


C# Uri.GetComponents方法代码示例

本文整理汇总了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);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:UriGetComponentsTest.cs

示例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;
        }
开发者ID:nlhepler,项目名称:mono,代码行数:25,代码来源:XmlUtil.cs

示例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;
		}
开发者ID:uvcteam,项目名称:univercity3d_uofo,代码行数:8,代码来源:CustomFileHandlerScript.cs

示例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;
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:36,代码来源:ODataPathParser.cs

示例5: WriteUri

 internal void WriteUri(Uri value)
 {
     writer.WriteString(value.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped));
 }
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:4,代码来源:XmlWriterDelegator.cs

示例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");
    }
开发者ID:johnhhm,项目名称:corefx,代码行数:11,代码来源:Uri.cs

示例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]");
 }
开发者ID:Corillian,项目名称:corefx,代码行数:6,代码来源:UriParserTest.cs

示例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;
        }
开发者ID:dmetzgar,项目名称:wcf,代码行数:36,代码来源:BaseUriWithWildcard.cs

示例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;
    }
开发者ID:tstratton,项目名称:cd-explorer-folder,代码行数:62,代码来源:Program.cs

示例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
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:14,代码来源:Uri.MethodsTests.cs

示例11: GetComponents

 public void GetComponents(Uri uri, UriComponents components, UriFormat format, string expected)
 {
     Assert.Equal(expected, uri.GetComponents(components, format));
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:4,代码来源:Uri.MethodsTests.cs

示例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));
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:11,代码来源:UriMailToTest.cs

示例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());
        }
开发者ID:T-REX-XP,项目名称:serialwifi,代码行数:13,代码来源:Uri.cs

示例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;
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:22,代码来源:SpnDictionary.cs

示例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);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:36,代码来源:FtpControlStream.cs


注:本文中的Uri.GetComponents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。