本文整理汇总了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;
}
示例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;
}
}
示例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);
}
示例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);
*/
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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);
}
}