Csharp/C Sharp by API/System.Resources/ResourceWriter

Материал из .Net Framework эксперт
Версия от 12:12, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

new ResourceWriter

 

using System;
using System.Globalization;
using System.Resources;
using System.Collections;
class Class1 {
  static void Main(string[] args) {
      ResourceWriter resourceWriter = new ResourceWriter("nfex.resources");
      resourceWriter.AddResource("key 1", "First value");
      resourceWriter.AddResource("key 2", "Second value");
      resourceWriter.AddResource("key 3", "Third value");
      resourceWriter.Generate();
      resourceWriter.Close();
      ResourceReader resourceReader = new ResourceReader("nfex.resources");
      IDictionaryEnumerator resourceReaderEn = resourceReader.GetEnumerator();
      while (resourceReaderEn.MoveNext())
      {
         Console.WriteLine("Name: {0} - Value: {1}", 
            resourceReaderEn.Key.ToString().PadRight(10, " "), 
            resourceReaderEn.Value);
      }
      resourceReader.Close();
   }
}


ResourceWriter.AddResource

 

using System;
using System.Globalization;
using System.Resources;
using System.Collections;
class Class1 {
  static void Main(string[] args) {
      ResourceWriter resourceWriter = new ResourceWriter("nfex.resources");
      resourceWriter.AddResource("key 1", "First value");
      resourceWriter.AddResource("key 2", "Second value");
      resourceWriter.AddResource("key 3", "Third value");
      resourceWriter.Generate();
      resourceWriter.Close();
      ResourceReader resourceReader = new ResourceReader("nfex.resources");
      IDictionaryEnumerator resourceReaderEn = resourceReader.GetEnumerator();
      while (resourceReaderEn.MoveNext())
      {
         Console.WriteLine("Name: {0} - Value: {1}", 
            resourceReaderEn.Key.ToString().PadRight(10, " "), 
            resourceReaderEn.Value);
      }
      resourceReader.Close();
   }
}


ResourceWriter.AddResource(String key, Image value)

 
  using System;
  using System.Resources;
  using System.Drawing;
  using System.Windows.Forms;
  using System.Reflection;
  class ResourceGenerator
  {
    static void Main(string[] args)
    {
      ResourceWriter rw;
      rw = new ResourceWriter("myResources.resources");
      rw.AddResource("anImage", new Bitmap("winter.jpg"));
      rw.AddResource("welcomeString", "www.nfex.ru");
      rw.Generate();
    }
  }


ResourceWriter.Generate()

 

using System;
using System.Globalization;
using System.Resources;
using System.Collections;
class Class1 {
  static void Main(string[] args) {
      ResourceWriter resourceWriter = new ResourceWriter("nfex.resources");
      resourceWriter.AddResource("key 1", "First value");
      resourceWriter.AddResource("key 2", "Second value");
      resourceWriter.AddResource("key 3", "Third value");
      resourceWriter.Generate();
      resourceWriter.Close();
      ResourceReader resourceReader = new ResourceReader("nfex.resources");
      IDictionaryEnumerator resourceReaderEn = resourceReader.GetEnumerator();
      while (resourceReaderEn.MoveNext())
      {
         Console.WriteLine("Name: {0} - Value: {1}", 
            resourceReaderEn.Key.ToString().PadRight(10, " "), 
            resourceReaderEn.Value);
      }
      resourceReader.Close();
   }
}