Csharp/C Sharp by API/System.Resources/ResourceManager — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:12, 26 мая 2010

new ResourceManager

 
//csc /res:StringTable.resources Test.cs

//File: Test.cs
using System;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
public class Test
{
   
    public static void Main(String[] a)
    {
        ResourceManager FormResources = new ResourceManager("StringTable", Assembly.GetExecutingAssembly());
        string          Message;
        
        Message = FormResources.GetString("Message");
        MessageBox.Show(Message);
    }
}
//resgen StringTable.txt

/* File:StringTable.txt
# String Table
Message = The button has been clicked.
*/


ResourceManager.CreateFileBasedResourceManager

 
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();
      //Loose resource example
      ResourceManager rm;
      rm = ResourceManager.CreateFileBasedResourceManager("nfex",".",null);
      Console.WriteLine(rm.GetString("key 1"));

   }
}


ResourceManager.GetString

 
//csc /res:StringTable.resources Test.cs

//File: Test.cs
using System;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
public class Test
{
   
    public static void Main(String[] a)
    {
        ResourceManager FormResources = new ResourceManager("StringTable", Assembly.GetExecutingAssembly());
        string          Message;
        
        Message = FormResources.GetString("Message");
        MessageBox.Show(Message);
    }
}
//resgen StringTable.txt

/* File:StringTable.txt
# String Table
#
Message = The button has been clicked.
*/