TryLookup() public method

public TryLookup ( System value, System &result ) : bool
value System
result System
return bool
Esempio n. 1
0
		public void EmptyAfterAdd ()
		{
			XmlDictionary d = new XmlDictionary ();
			XmlDictionaryString dns;
			d.Add ("foo");
			Assert.IsFalse (d.TryLookup (String.Empty, out dns), "#0");
			Assert.IsTrue (d.TryLookup ("foo", out dns), "#1");
			Assert.AreEqual (0, dns.Key, "#2");
		}
		public void IsLocalName ()
		{
			XmlDictionaryReader r = GetReader ("<root/>");
			r.Read ();

			Assert.IsTrue (r.IsLocalName ("root"), "#1");
			Assert.IsFalse (r.IsLocalName ("foo"), "#2");
			XmlDictionaryString ds;
			XmlDictionary dict = new XmlDictionary ();
			dict.Add ("root");
			dict.TryLookup ("root", out ds);
			Assert.IsTrue (r.IsLocalName (ds), "#3");
			dict.Add ("foo");
			dict.TryLookup ("foo", out ds);
			Assert.IsFalse (r.IsLocalName (ds), "#4");
		}
Esempio n. 3
0
        void WriteDictionaryIndex(XmlDictionaryString ds)
        {
            XmlDictionaryString ds2;
            bool isSession = false;
            int  idx       = ds.Key;

            if (ds.Dictionary != dict_ext)
            {
                isSession = true;
                if (dict_int.TryLookup(ds.Value, out ds2))
                {
                    ds = ds2;
                }
                if (!session.TryLookup(ds, out idx))
                {
                    session.TryAdd(dict_int.Add(ds.Value), out idx);
                }
            }
            if (idx >= 0x80)
            {
                writer.Write((byte)(0x80 + ((idx % 0x80) << 1) + (isSession ? 1 : 0)));
                writer.Write((byte)((byte)(idx / 0x80) << 1));
            }
            else
            {
                writer.Write((byte)(((idx % 0x80) << 1) + (isSession ? 1 : 0)));
            }
        }
 private static XmlDictionaryString AddToDictionary(XmlDictionary dictionary, string s)
 {
     XmlDictionaryString str;
     if (!dictionary.TryLookup(s, out str))
     {
         str = dictionary.Add(s);
     }
     return str;
 }
Esempio n. 5
0
		public void SimpleUse ()
		{
			XmlDictionary d1 = new XmlDictionary ();
			XmlDictionaryString dns;
			Assert.IsFalse (d1.TryLookup (String.Empty, out dns), "#0");
			XmlDictionaryString s1 = d1.Add ("foo");
			XmlDictionary d2 = new XmlDictionary ();
			XmlDictionaryString s2 = d2.Add ("foo");
			XmlDictionaryString o = null;
			Assert.AreEqual ("foo", s1.ToString (), "#1");
			Assert.AreEqual (0, s1.Key, "#2");
			Assert.AreEqual (0, s1.Key, "#3");
			Assert.IsTrue (d1.TryLookup ("foo", out o), "#4");
			Assert.IsTrue (d1.TryLookup (s1, out o), "#5");
			Assert.IsFalse (d1.TryLookup (s2, out o), "#6");
			Assert.AreEqual (0, XmlDictionaryString.Empty.Key, "#7");
			Assert.AreEqual (false, XmlDictionaryString.Empty.Dictionary == XmlDictionary.Empty, "#8");
			XmlDictionaryString dummy;
			Assert.AreEqual (false, XmlDictionary.Empty.TryLookup ("", out dummy), "#9");

		}
		public void WriteElementWithNS ()
		{
			byte [] bytes = new byte [] {
				0x42, 0, 10, 2, 0x98, 3, 0x61, 0x61,
				0x61, 0x42, 0, 0x42, 2, 1, 1, 1};
			XmlDictionaryString ds;
			MemoryStream ms = new MemoryStream ();
			XmlDictionary dic = new XmlDictionary ();
			XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter (ms, dic, null);
			w.WriteStartElement (dic.Add ("FOO"), dic.Add ("foo"));
			Assert.IsTrue (dic.TryLookup ("foo", out ds), "#1");
			Assert.AreEqual (1, ds.Key, "#2");
			w.WriteString ("aaa");
			w.WriteStartElement (dic.Add ("FOO"), dic.Add ("foo"));
			w.WriteStartElement (dic.Add ("foo"), dic.Add ("foo"));
			w.Close ();
			Assert.AreEqual (bytes, ms.ToArray (), "result");
/*
			byte [] bytes2 = new byte [] {
				0x42, 1, 10, 2, 0x98, 3, 0x61, 0x61,
				0x61, 0x42, 0, 0x42, 2, 1, 1, 1};
				
			XmlDictionaryReader dr = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes2), dic, new XmlDictionaryReaderQuotas ());
			try {
				dr.Read ();
				Assert.Fail ("dictionary index 1 should be regarded as invalid.");
			} catch (XmlException) {
			}
*/
		}
		public void UseStandardSession2 ()
		{
			MemoryStream ms = new MemoryStream ();
			XmlBinaryWriterSession session =
				new XmlBinaryWriterSession ();
			XmlDictionary dic = new XmlDictionary ();
			XmlDictionaryString x = dic.Add ("urn:foo");
			XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
			w.WriteStartElement (dic.Add ("FOO"), x);
			w.WriteStartElement (dic.Add ("blah"), x);
			w.WriteStartElement (dic.Add ("blabla"), x);
			w.Close ();
			Assert.AreEqual (new byte [] {0x42, 2, 0x0A, 0, 0x42, 4, 0x42, 6, 1, 1, 1}, ms.ToArray (), "#1");

			XmlDictionaryString ds;
			Assert.IsTrue (dic.TryLookup (0, out ds), "#2-1");
			Assert.AreEqual ("urn:foo", ds.Value, "#2-2");
			Assert.AreEqual (0, ds.Key, "#2-3");
			Assert.IsTrue (dic.TryLookup (1, out ds), "#3-1");
			Assert.AreEqual ("FOO", ds.Value, "#3-2");
			Assert.AreEqual (1, ds.Key, "#3-3");
			Assert.IsTrue (dic.TryLookup (2, out ds), "#4-1");
			Assert.AreEqual ("blah", ds.Value, "#4-2");
			Assert.AreEqual (2, ds.Key, "#4-3");
			Assert.IsTrue (dic.TryLookup (3, out ds), "#5-1");
			Assert.AreEqual ("blabla", ds.Value, "#5-2");
			Assert.AreEqual (3, ds.Key, "#5-3");
		}
 private static XmlDictionaryString AddToDictionary(XmlDictionary dictionary, string s)
 {
     XmlDictionaryString dictionaryString;
     if (!dictionary.TryLookup(s, out dictionaryString))
     {
         dictionaryString = dictionary.Add(s);
     }
     return dictionaryString;
 }