Equals() public method

public Equals ( object o ) : bool
o object
return bool
		// Methods
		public bool Check (Evidence evidence)
		{
			if (evidence == null)
				return false;

			string codebase = Assembly.GetCallingAssembly ().CodeBase;
			Uri local = new Uri (codebase);
			Url ucode = new Url (codebase);

			// *both* ApplicationDirectory and Url must be in *Host* evidences
			bool adir = false;
			bool url = false;
			IEnumerator e = evidence.GetHostEnumerator ();
			while (e.MoveNext ()) {
				object o = e.Current;

				if (!adir && (o is ApplicationDirectory)) {
					ApplicationDirectory ad = (o as ApplicationDirectory);
					string s = ad.Directory;
					adir = (String.Compare (s, 0, local.ToString (), 0, s.Length, true, CultureInfo.InvariantCulture) == 0);
				}
				else if (!url && (o is Url)) {
					url = ucode.Equals (o);
				}

				// got both ?
				if (adir && url)
					return true;
			}
			return false;
		}
        /// <summary>Determines whether the membership condition is satisfied by the specified evidence.</summary>
        /// <returns>true if the specified evidence satisfies the membership condition; otherwise, false.</returns>
        /// <param name="evidence">The evidence set against which to make the test. </param>
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }
            string      codeBase       = Assembly.GetCallingAssembly().CodeBase;
            Uri         uri            = new Uri(codeBase);
            Url         url            = new Url(codeBase);
            bool        flag           = false;
            bool        flag2          = false;
            IEnumerator hostEnumerator = evidence.GetHostEnumerator();

            while (hostEnumerator.MoveNext())
            {
                object obj = hostEnumerator.Current;
                if (!flag && obj is ApplicationDirectory)
                {
                    ApplicationDirectory applicationDirectory = obj as ApplicationDirectory;
                    string directory = applicationDirectory.Directory;
                    flag = (string.Compare(directory, 0, uri.ToString(), 0, directory.Length, true, CultureInfo.InvariantCulture) == 0);
                }
                else if (!flag2 && obj is Url)
                {
                    flag2 = url.Equals(obj);
                }
                if (flag && flag2)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        // Methods
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }

            string codebase = Assembly.GetCallingAssembly().CodeBase;
            Uri    local    = new Uri(codebase);
            Url    ucode    = new Url(codebase);

            // *both* ApplicationDirectory and Url must be in *Host* evidences
            bool        adir = false;
            bool        url  = false;
            IEnumerator e    = evidence.GetHostEnumerator();

            while (e.MoveNext())
            {
                object o = e.Current;

                if (!adir && (o is ApplicationDirectory))
                {
                    ApplicationDirectory ad = (o as ApplicationDirectory);
                    string s = ad.Directory;
                    adir = (String.Compare(s, 0, local.ToString(), 0, s.Length, true, CultureInfo.InvariantCulture) == 0);
                }
                else if (!url && (o is Url))
                {
                    url = ucode.Equals(o);
                }

                // got both ?
                if (adir && url)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 4
0
		public void Url_LoneStar () 
		{
			Url u = new Url ("*");
#if NET_2_0
			Assert.AreEqual ("*", u.Value, "Value");
			Assert.AreEqual ("<System.Security.Policy.Url version=\"1\">" + Environment.NewLine + "<Url>*</Url>" + Environment.NewLine + "</System.Security.Policy.Url>" + Environment.NewLine, u.ToString (), "ToString");
#else
			Assert.AreEqual ("file://*", u.Value, "Value");
			Assert.AreEqual ("<System.Security.Policy.Url version=\"1\">" + Environment.NewLine + "   <Url>file://*</Url>" + Environment.NewLine + "</System.Security.Policy.Url>" + Environment.NewLine, u.ToString (), "ToString");
#endif
			Url u2 = (Url) u.Copy ();
			Assert.AreEqual (u.Value, u2.Value, "Copy.Value");
			Assert.AreEqual (u.GetHashCode (), u2.GetHashCode (), "Copy.GetHashCode");

			UrlIdentityPermission uip = (UrlIdentityPermission) u.CreateIdentityPermission (null);
			Assert.AreEqual (u.Value, uip.Url, "CreateIdentityPermission");

			Assert.IsTrue (u.Equals (u2), "Equals");
			Url u3 = new Url ("index.html");
			Assert.IsFalse (u.Equals (u3), "!Equals(*)");

			u2 = new Url ("file://*");
			Assert.AreEqual ("file://*", u2.Value, "Value-file://*");
			Assert.IsTrue (u.Equals (u2), "Equals-file://*");
		}
Esempio n. 5
0
		public void EqualsNull () 
		{
			Url u = new Url ("http://www.go-mono.com");
			Assert.IsFalse (u.Equals (null), "EqualsNull");
		}
Esempio n. 6
0
		public void EqualsPartial () 
		{
			Url u1 = new Url ("http://www.go-mono.com/index.html");
			Url u2 = new Url ("http://www.go-mono.com/*");
			Assert.IsFalse (u1.Equals (u2), "Partial:1-2");
			Assert.IsFalse (u2.Equals (u1), "Partial:2-1");
		}
Esempio n. 7
0
		public void EqualsCaseSensitive () 
		{
			Url u1 = new Url ("http://www.go-mono.com");
			Url u2 = new Url ("http://www.Go-Mono.com");
			Assert.IsTrue (u1.Equals (u2), "CaseSensitive");
		}
Esempio n. 8
0
		public void Url_GoMonoWebUrl () 
		{
			string url = "http://www.go-mono.com";
			Url u = new Url (url);

			Assert.IsTrue (u.Value.StartsWith (url), "Value");
#if NET_2_0
			// no spaces in XML, no ending '/' on url
			Assert.AreEqual ("<System.Security.Policy.Url version=\"1\">" + Environment.NewLine + "<Url>http://www.go-mono.com</Url>" + Environment.NewLine + "</System.Security.Policy.Url>" + Environment.NewLine, u.ToString (), "ToString");
#else
			Assert.AreEqual ("<System.Security.Policy.Url version=\"1\">" + Environment.NewLine + "   <Url>http://www.go-mono.com/</Url>" + Environment.NewLine + "</System.Security.Policy.Url>" + Environment.NewLine, u.ToString (), "ToString");
#endif
			Url u2 = (Url) u.Copy ();
			Assert.AreEqual (u.Value, u2.Value, "Copy.Value");
			Assert.AreEqual (u.GetHashCode (), u2.GetHashCode (), "Copy.GetHashCode");

			UrlIdentityPermission uip = (UrlIdentityPermission) u.CreateIdentityPermission (null);
			Assert.AreEqual (u.Value, uip.Url, "CreateIdentityPermission");

			Assert.IsTrue (u.Equals (u2), "Equals");
			Url u3 = new Url ("go-mono.com");
			Assert.IsFalse (u.Equals (u3), "!Equals");
		}