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


C# Uri.Equals方法代码示例

本文整理汇总了C#中Uri.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.Equals方法的具体用法?C# Uri.Equals怎么用?C# Uri.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Uri的用法示例。


在下文中一共展示了Uri.Equals方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetType

 public override string GetType(Uri uri) {
     if (uri.Equals(Uri.WithAppendedPath(CONTENT_URI, "foo.txt")) ||
             uri.Equals(Uri.WithAppendedPath(CONTENT_URI, "bar.txt"))) {
         return "text/plain";
     }
     return null;
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:7,代码来源:SharingSupportProvider.cs

示例2: Contains

        /// <param name="codeBaseUri">Uri pointing to the assembly</param>
        public static bool Contains(Uri codeBaseUri)
        {
            if(codeBaseUri == null)
            {
                Debug.Fail("codeBaseUri == null");
                return false;
            }

            lock(GlobalAssemblyCache.Lock)
            {
                if(!GlobalAssemblyCache.FusionLoaded)
                {
                    GlobalAssemblyCache.FusionLoaded = true;
                    System.Reflection.Assembly systemAssembly = typeof(object).Assembly;
                    //^ assume systemAssembly != null && systemAssembly.Location != null;
                    string dir = Path.GetDirectoryName(systemAssembly.Location);
                    //^ assume dir != null;
                    GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll"));
                }

                IAssemblyEnum assemblyEnum;
                int rc = GlobalAssemblyCache.CreateAssemblyEnum(out assemblyEnum, null, null, GAC, 0);

                if(rc < 0 || assemblyEnum == null)
                    return false;

                IApplicationContext applicationContext;
                IAssemblyName currentName;

                while(assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0)
                {
                    //^ assume currentName != null;
                    AssemblyName assemblyName = new AssemblyName(currentName);
                    string scheme = codeBaseUri.Scheme;

                    if(scheme != null && assemblyName.CodeBase.StartsWith(scheme))
                    {
                        try
                        {
                            Uri foundUri = new Uri(assemblyName.CodeBase);
                            if(codeBaseUri.Equals(foundUri))
                                return true;
                        }
                        catch(Exception)
                        {
                        }
                    }
                }

                return false;
            }
        }
开发者ID:modulexcite,项目名称:SHFB-1,代码行数:53,代码来源:AssemblyCache.cs

示例3: UriEqual

 // SxS: URIs are resolved only to be compared. No resource exposure. It's OK to suppress the SxS warning.
 private bool UriEqual(Uri uri1, string uri1Str, string uri2Str, XmlResolver resolver)
 {
     if (resolver == null)
     {
         return uri1Str == uri2Str;
     }
     if (uri1 == null)
     {
         uri1 = resolver.ResolveUri(null, uri1Str);
     }
     Uri uri2 = resolver.ResolveUri(null, uri2Str);
     return uri1.Equals(uri2);
 }
开发者ID:chcosta,项目名称:corefx,代码行数:14,代码来源:XmlTextReaderImpl.cs

示例4: TestCompare

    public static void TestCompare()
    {
        Uri uri1 = new Uri("http://www.contoso.com/path?name#frag");
        Uri uri2 = new Uri("http://www.contosooo.com/path?name#slag");
        Uri uri2a = new Uri("http://www.contosooo.com/path?name#slag");

        int i;

        i = Uri.Compare(uri1, uri2, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.CurrentCulture);
        Assert.Equal(i, -1);

        i = Uri.Compare(uri1, uri2, UriComponents.Query, UriFormat.UriEscaped, StringComparison.CurrentCulture);
        Assert.Equal(i, 0);

        i = Uri.Compare(uri1, uri2, UriComponents.Query | UriComponents.Fragment, UriFormat.UriEscaped, StringComparison.CurrentCulture);
        Assert.Equal(i, -1);

        bool b;

        b = uri1.Equals(uri2);
        Assert.False(b);

        b = uri1 == uri2;
        Assert.False(b);

        b = uri1 != uri2;
        Assert.True(b);

        b = uri2.Equals(uri2a);
        Assert.True(b);

        b = uri2 == uri2a;
        Assert.True(b);

        b = uri2 != uri2a;
        Assert.False(b);
        // Blocked: Globalization
        /*
        int h2 = uri2.GetHashCode();
        int h2a = uri2a.GetHashCode();
        Assert.AreEqual(h2, h2a);
        */
    }
开发者ID:johnhhm,项目名称:corefx,代码行数:43,代码来源:Uri.cs

示例5: FindSchemaByNSAndUrl

 internal XmlSchema FindSchemaByNSAndUrl(Uri schemaUri, string ns, DictionaryEntry[] locationsTable) {
     if (schemaUri == null || schemaUri.OriginalString.Length == 0) {
         return null;
     }
     XmlSchema schema = null;
     if (locationsTable == null) {
         schema = (XmlSchema)schemaLocations[schemaUri];
     }
     else {
         for (int i = 0; i < locationsTable.Length; i++) {
             if (schemaUri.Equals(locationsTable[i].Key)) {
                 schema = (XmlSchema)locationsTable[i].Value;
                 break;
             }
         }
     }
     if (schema != null) {
         Debug.Assert(ns != null);
         string tns = schema.TargetNamespace == null ? string.Empty : schema.TargetNamespace;
         if (tns == ns) {
             return schema;
         }
         else if (tns == string.Empty) { //There could be a chameleon for same ns
             ChameleonKey cKey = new ChameleonKey(ns, schemaUri);
             schema = (XmlSchema)chameleonSchemas[cKey]; //Need not clone if a schema for that namespace already exists
         }
         else {
             schema = null;
         }
     }
     return schema;
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:32,代码来源:xmlschemaset.cs

示例6: UriEquals

        internal static bool UriEquals(Uri u1, Uri u2, bool ignoreCase, bool includeHostInComparison, bool includePortInComparison)
        {
            // PERF: Equals compares everything but UserInfo and Fragments.  It's more strict than
            //       we are, and faster, so it is done first.
            if (u1.Equals(u2))
            {
                return true;
            }

            if (u1.Scheme != u2.Scheme)  // Uri.Scheme is always lowercase
            {
                return false;
            }
            if (includePortInComparison)
            {
                if (u1.Port != u2.Port)
                {
                    return false;
                }
            }
            if (includeHostInComparison)
            {
                if (string.Compare(u1.Host, u2.Host, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return false;
                }
            }

            if (string.Compare(u1.AbsolutePath, u2.AbsolutePath, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0)
            {
                return true;
            }

            // Normalize for trailing slashes
            string u1Path = u1.GetComponents(UriComponents.Path, UriFormat.Unescaped);
            string u2Path = u2.GetComponents(UriComponents.Path, UriFormat.Unescaped);
            int u1Len = (u1Path.Length > 0 && u1Path[u1Path.Length - 1] == '/') ? u1Path.Length - 1 : u1Path.Length;
            int u2Len = (u2Path.Length > 0 && u2Path[u2Path.Length - 1] == '/') ? u2Path.Length - 1 : u2Path.Length;
            if (u2Len != u1Len)
            {
                return false;
            }
            return string.Compare(u1Path, 0, u2Path, 0, u1Len, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:44,代码来源:EndpointAddress.cs

示例7: AddPermission

        // <
        internal void AddPermission(NetworkAccess access, Uri uri) {
            if (uri == null) {
                throw new ArgumentNullException("uri");
            }

            if (m_noRestriction)
            {
                return;
            }

            ArrayList lists = new ArrayList();
            if ((access & NetworkAccess.Connect) != 0 && !m_UnrestrictedConnect)
                lists.Add(m_connectList);
            if ((access & NetworkAccess.Accept) != 0 && !m_UnrestrictedAccept)
                lists.Add(m_acceptList);

            foreach (ArrayList list in lists)
            {
                // avoid duplicated uris in the list
                bool found = false;
                foreach (object permObj in list) {
                    if ((permObj is Uri) && uri.Equals(permObj))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    list.Add(uri);
                }
            }
        }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:33,代码来源:WebPermission.cs

示例8: MakeRelative

    // Return the relative vpath path from one rooted vpath to another
    internal static string MakeRelative(string from, string to) {

        // If either path is app relative (~/...), make it absolute, since the Uri
        // class wouldn't know how to deal with it.
        from = MakeVirtualPathAppAbsolute(from);
        to = MakeVirtualPathAppAbsolute(to);

        // Make sure both virtual paths are rooted
        if (!IsRooted(from))
            throw new ArgumentException(SR.GetString(SR.Path_must_be_rooted, from));
        if (!IsRooted(to))
            throw new ArgumentException(SR.GetString(SR.Path_must_be_rooted, to));

        // Remove the query string, so that System.Uri doesn't corrupt it
        string queryString = null;
        if (to != null) {
            int iqs = to.IndexOf('?');
            if (iqs >= 0) {
                queryString = to.Substring(iqs);
                to = to.Substring(0, iqs);
            }
        }

        // Uri's need full url's so, we use a dummy root
        Uri fromUri = new Uri(dummyProtocolAndServer + from);
        Uri toUri = new Uri(dummyProtocolAndServer + to);

        string relativePath;

        // VSWhidbey 144946: If to and from points to identical path (excluding query and fragment), just use them instead
        // of returning an empty string.
        if (fromUri.Equals(toUri)) {
            int iPos = to.LastIndexOfAny(s_slashChars);

            if (iPos >= 0) {

                // If it's the same directory, simply return "./"
                // Browsers should interpret "./" as the original directory.
                if (iPos == to.Length - 1) {
                    relativePath = "./";
                }
                else {
                    relativePath = to.Substring(iPos + 1);
                }
            }
            else {
                relativePath = to;
            }
        }
        else {
// To avoid deprecation warning.  It says we should use MakeRelativeUri instead (which returns a Uri),
// but we wouldn't gain anything from it.  The way we use MakeRelative is hacky anyway (fake protocol, ...),
// and I don't want to take the chance of breaking something with this change.
#pragma warning disable 0618
            relativePath = fromUri.MakeRelative(toUri);
#pragma warning restore 0618
        }

        // Note that we need to re-append the query string and fragment (e.g. #anchor)
        return relativePath + queryString + toUri.Fragment;
    }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:62,代码来源:UrlPath.cs

示例9: Equals

 public void Equals(Uri uri1, object obj, bool expected)
 {
     Uri uri2 = obj as Uri;
     if (uri1 != null)
     {
         Assert.Equal(expected, uri1.Equals(obj));
         if (uri2 != null)
         {
             Assert.Equal(expected, uri1.GetHashCode().Equals(uri2.GetHashCode()));
         }
     }
     if (!(obj is string))
     {
         Assert.Equal(expected, uri1 == uri2);
         Assert.Equal(!expected, uri1 != uri2);
     }
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:17,代码来源:Uri.MethodsTests.cs


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