当前位置: 首页>>代码示例>>C#>>正文


C# ResourceManager类代码示例

本文整理汇总了C#中System.Resources.ResourceManager的典型用法代码示例。如果您正苦于以下问题:C# ResourceManager类的具体用法?C# ResourceManager怎么用?C# ResourceManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResourceManager类属于System.Resources命名空间,在下文中一共展示了ResourceManager类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.Resources;
using System.Reflection;
using System.Threading;
using System.Globalization;

class Example 
{
    public static void Main() 
    {
    string day;
    string year;
    string holiday;
    string celebrate = "{0} will occur on {1} in {2}.\n";

    // Create a resource manager. 
    ResourceManager rm = new ResourceManager("rmc", 
                             typeof(Example).Assembly);

    Console.WriteLine("Obtain resources using the current UI culture.");

    // Get the resource strings for the day, year, and holiday 
    // using the current UI culture. 
    day  = rm.GetString("day");
    year = rm.GetString("year");
    holiday = rm.GetString("holiday");
    Console.WriteLine(celebrate, holiday, day, year);

    // Obtain the es-MX culture.
    CultureInfo ci = new CultureInfo("es-MX");

    Console.WriteLine("Obtain resources using the es-MX culture.");

   // Get the resource strings for the day, year, and holiday 
   // using the specified culture. 
    day  = rm.GetString("day", ci);
    year = rm.GetString("year", ci);
    holiday = rm.GetString("holiday", ci);
// ---------------------------------------------------------------
// Alternatively, comment the preceding 3 code statements and 
// uncomment the following 4 code statements:
// ----------------------------------------------------------------
// Set the current UI culture to "es-MX" (Spanish-Mexico).
//    Thread.CurrentThread.CurrentUICulture = ci;

// Get the resource strings for the day, year, and holiday 
// using the current UI culture. Use those strings to 
// display a message. 
//    day  = rm.GetString("day");
//    year = rm.GetString("year");
//    holiday = rm.GetString("holiday");
// ---------------------------------------------------------------

// Regardless of the alternative that you choose, display a message 
// using the retrieved resource strings.
    Console.WriteLine(celebrate, holiday, day, year);
    }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:59,代码来源:ResourceManager

输出:

Obtain resources using the current UI culture.
   "5th of May" will occur on Friday in 2006.
   
   Obtain resources using the es-MX culture.
   "Cinco de Mayo" will occur on Viernes in 2006.

示例2: Main

//引入命名空间
using System;
using System.Resources;

public class Example
{
   public static void Main()
   {
      ResourceManager rm = new ResourceManager("Strings", 
                               typeof(Example).Assembly);
      string timeString = rm.GetString("TimeHeader");
      Console.WriteLine("{0} {1:T}", timeString, DateTime.Now);   
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:14,代码来源:ResourceManager

输出:

The current time is 2:03:14 PM

示例3: Main

//引入命名空间
using System;
using System.Globalization;
using System.Resources;
using System.Threading;

public class Example
{
   public static void Main()
   {
      // Create array of supported cultures
      string[] cultures = {"en-CA", "en-US", "fr-FR", "ru-RU" };
      Random rnd = new Random();
      int cultureNdx = rnd.Next(0, cultures.Length);
      CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
      ResourceManager rm = new ResourceManager("Greetings", typeof(Example).Assembly);
      try {
         CultureInfo newCulture = new CultureInfo(cultures[cultureNdx]);
         Thread.CurrentThread.CurrentCulture = newCulture;
         Thread.CurrentThread.CurrentUICulture = newCulture;
         string greeting = String.Format("The current culture is {0}.\n{1}",
                                         Thread.CurrentThread.CurrentUICulture.Name,
                                         rm.GetString("HelloString"));
         Console.WriteLine(greeting);
      }
      catch (CultureNotFoundException e) {
         Console.WriteLine("Unable to instantiate culture {0}", e.InvalidCultureName);
      }
      finally {
         Thread.CurrentThread.CurrentCulture = originalCulture;
         Thread.CurrentThread.CurrentUICulture = originalCulture;
      }
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:34,代码来源:ResourceManager

输出:

The current culture is ru-RU.
Всем привет!

示例4: Main

//引入命名空间
using System;
using System.Globalization;
using System.Resources;
using System.Threading;

[assembly:NeutralResourcesLanguage("en")]

public class Example
{
   public static void Main()
   {
      string[] cultureNames = { "en-US", "fr-FR", "ru-RU", "sv-SE" };
      ResourceManager rm = new ResourceManager("DateStrings",
                                               typeof(Example).Assembly);
      
      foreach (var cultureName in cultureNames) {
         CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureName);
         Thread.CurrentThread.CurrentCulture = culture; 
         Thread.CurrentThread.CurrentUICulture = culture;

         Console.WriteLine("Current UI Culture: {0}", 
                           CultureInfo.CurrentUICulture.Name);
         string dateString = rm.GetString("DateStart");
         Console.WriteLine("{0} {1:M}.\n", dateString, DateTime.Now);                           
      }                                           
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:28,代码来源:ResourceManager

输出:

Current UI Culture: en-US
Today is February 03.

Current UI Culture: fr-FR
Aujourd'hui, c'est le 3 février

Current UI Culture: ru-RU
Сегодня февраля 03.

Current UI Culture: sv-SE
Today is den 3 februari.

示例5: Main

//引入命名空间
using System;
using System.IO;
using System.Reflection;
using System.Resources;

public class Example
{
   public static void Main()
   {
      if (Environment.GetCommandLineArgs().Length == 1) { 
         Console.WriteLine("No filename.");
         return;
      }
      
      string filename = Environment.GetCommandLineArgs()[1].Trim();
      // Check whether the file exists.
      if (! File.Exists(filename)) {
         Console.WriteLine("{0} does not exist.", filename);
         return;
      }   
      
      // Try to load the assembly.
      Assembly assem = Assembly.LoadFrom(filename);
      Console.WriteLine("File: {0}", filename);
         
      // Enumerate the resource files.
      string[] resNames = assem.GetManifestResourceNames();
      if (resNames.Length == 0)
         Console.WriteLine("   No resources found.");

      foreach (var resName in resNames)
         Console.WriteLine("   Resource: {0}", resName.Replace(".resources", ""));

      Console.WriteLine();
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:37,代码来源:ResourceManager

示例6: 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.

*/
开发者ID:C#程序员,项目名称:System.Resources,代码行数:30,代码来源:ResourceManager


注:本文中的System.Resources.ResourceManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。