public void GetMetadataEnumerator ()
		{
			string refFile = Path.Combine (_tempDirectory, "32x32.ico");
			WriteEmbeddedResource ("32x32.ico", refFile);

			string resxFile = Path.Combine (_tempDirectory, "resources.resx");
			using (StreamWriter sw = new StreamWriter (resxFile, false, Encoding.UTF8)) {
				sw.Write (string.Format (CultureInfo.InvariantCulture,
					_resXFileRefTemplate, ResXResourceWriter.ResMimeType, "1.0",
					Consts.AssemblySystem_Windows_Forms, refFile,
					typeof (Bitmap).AssemblyQualifiedName, string.Empty,
					Consts.AssemblyCorlib));
			}

			using (ResXResourceReader r = new ResXResourceReader (resxFile)) {
				IDictionaryEnumerator enumerator = r.GetMetadataEnumerator ();
				Assert.IsTrue (enumerator.MoveNext (), "#A1");
				Assert.IsNotNull (enumerator.Current, "#A2");
				Assert.AreEqual ("panel_label.Locked", enumerator.Key, "#A3");
				Assert.AreEqual(typeof(bool), enumerator.Value.GetType(), "#A4");
				Assert.IsTrue ((bool) enumerator.Value, "#A5");
				Assert.IsFalse (enumerator.MoveNext (), "#A6");
			}

			using (ResXResourceReader r = new ResXResourceReader (resxFile)) {
				r.UseResXDataNodes = true;
				IDictionaryEnumerator enumerator = r.GetMetadataEnumerator ();
				Assert.IsFalse (enumerator.MoveNext (), "#B1");
			}
		}
Exemplo n.º 2
0
		public void LoadFile(string filename, Stream stream)
		{
			resources.Clear();
			metadata.Clear();
			switch (Path.GetExtension(filename).ToLowerInvariant()) {
				case ".resx":
					ResXResourceReader rx = new ResXResourceReader(stream);
					rx.BasePath = Path.GetDirectoryName(filename);
					IDictionaryEnumerator n = rx.GetEnumerator();
					while (n.MoveNext())
						if (!resources.ContainsKey(n.Key.ToString()))
						resources.Add(n.Key.ToString(), new ResourceItem(n.Key.ToString(), n.Value));
					
					n = rx.GetMetadataEnumerator();
					while (n.MoveNext())
						if (!metadata.ContainsKey(n.Key.ToString()))
						metadata.Add(n.Key.ToString(), new ResourceItem(n.Key.ToString(), n.Value));
					
					rx.Close();
					break;
				case ".resources":
					ResourceReader rr=null;
					try {
						rr = new ResourceReader(stream);
						foreach (DictionaryEntry entry in rr) {
							if (!resources.ContainsKey(entry.Key.ToString()))
								resources.Add(entry.Key.ToString(), new ResourceItem(entry.Key.ToString(), entry.Value));
						}
					}
					finally {
						if (rr != null) {
							rr.Close();
						}
					}
					break;
			}
			InitializeListView();
		}
Exemplo n.º 3
0
		public void LoadFile(FileName filename, Stream stream)
		{
			resources.Clear();
			metadata.Clear();
			switch (Path.GetExtension(filename).ToLowerInvariant()) {
				case ".resx":
					ResXResourceReader rx = new ResXResourceReader(stream);
					ITypeResolutionService typeResolver = null;
					rx.BasePath = Path.GetDirectoryName(filename);
					rx.UseResXDataNodes = true;
					IDictionaryEnumerator n = rx.GetEnumerator();
					while (n.MoveNext()) {
						if (!resources.ContainsKey(n.Key.ToString())) {
							ResXDataNode node = (ResXDataNode)n.Value;
							resources.Add(n.Key.ToString(), new ResourceItem(node.Name, node.GetValue(typeResolver), node.Comment));
						}
					}
					
					n = rx.GetMetadataEnumerator();
					while (n.MoveNext()) {
						if (!metadata.ContainsKey(n.Key.ToString())) {
							ResXDataNode node = (ResXDataNode)n.Value;
							metadata.Add(n.Key.ToString(), new ResourceItem(node.Name, node.GetValue(typeResolver)));
						}
					}
					
					rx.Close();
					break;
				case ".resources":
					ResourceReader rr=null;
					try {
						rr = new ResourceReader(stream);
						foreach (DictionaryEntry entry in rr) {
							if (!resources.ContainsKey(entry.Key.ToString()))
								resources.Add(entry.Key.ToString(), new ResourceItem(entry.Key.ToString(), entry.Value));
						}
					}
					finally {
						if (rr != null) {
							rr.Close();
						}
					}
					break;
			}
			InitializeListView();
		}