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


C# ResourceManager.GetObject方法代码示例

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


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

示例1: PersonTable

//引入命名空间
using System;

[Serializable] public struct PersonTable
{
   public readonly int nColumns;
   public readonly string column1; 
   public readonly string column2;
   public readonly string column3; 
   public readonly int width1;
   public readonly int width2;
   public readonly int width3;
   
   public PersonTable(string column1, string column2, string column3,
                  int width1, int width2, int width3)
   {
      this.column1 = column1;
      this.column2 = column2;
      this.column3 = column3;
      this.width1 = width1;
      this.width2 = width2;
      this.width3 = width3;
      this.nColumns = typeof(PersonTable).GetFields().Length / 2; 
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:25,代码来源:ResourceManager.GetObject

示例2: Main

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

public class CreateResource
{
   public static void Main()
   {
      PersonTable table = new PersonTable("Name", "Employee Number", 
                                          "Age", 30, 18, 5);
      ResXResourceWriter rr = new ResXResourceWriter(@".\UIResources.resx");
      rr.AddResource("TableName", "Employees of Acme Corporation");
      rr.AddResource("Employees", table);
      rr.Generate();
      rr.Close();
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:17,代码来源:ResourceManager.GetObject

示例3: NeutralResourcesLanguageAttribute

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

[assembly: NeutralResourcesLanguageAttribute("en")]

public class Example
{
   public static void Main()
   {
      string fmtString = String.Empty;
      ResourceManager rm = new ResourceManager("UIResources", typeof(Example).Assembly);       
      string title = rm.GetString("TableName");
      PersonTable tableInfo = (PersonTable) rm.GetObject("Employees");

      if (! String.IsNullOrEmpty(title)) {
         fmtString = "{0," + ((Console.WindowWidth + title.Length) / 2).ToString() + "}"; 
         Console.WriteLine(fmtString, title);      
         Console.WriteLine();
      }

      for (int ctr = 1; ctr <= tableInfo.nColumns; ctr++) {
         string columnName = "column"  + ctr.ToString();
         string widthName = "width" + ctr.ToString();
         string value = tableInfo.GetType().GetField(columnName).GetValue(tableInfo).ToString();
         int width = (int) tableInfo.GetType().GetField(widthName).GetValue(tableInfo);
         fmtString = "{0,-" + width.ToString() + "}";
         Console.Write(fmtString, value);
      }      
      Console.WriteLine();
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:32,代码来源:ResourceManager.GetObject

示例4: Numbers

//引入命名空间
using System;

[Serializable] public class Numbers
{
   public readonly string One;
   public readonly string Two;
   public readonly string Three;
   public readonly string Four;
   public readonly string Five;
   public readonly string Six;
   public readonly string Seven;
   public readonly string Eight;
   public readonly string Nine;
   public readonly string Ten;

   public Numbers(string one, string two, string three, string four, 
                  string five, string six, string seven, string eight,
                  string nine, string ten)
   {                     
      this.One = one;
      this.Two = two;
      this.Three = three;
      this.Four = four;
      this.Five = five;
      this.Six = six;
      this.Seven = seven;
      this.Eight = eight;
      this.Nine = nine;
      this.Ten = ten;                                    
   }                  
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:32,代码来源:ResourceManager.GetObject

示例5: Main

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

public class CreateResource
{
   public static void Main()
   {
      Numbers en = new Numbers("one", "two", "three", "four", "five",
                               "six", "seven", "eight", "nine", "ten");
      CreateResourceFile(en, "en");
      Numbers fr = new Numbers("un", "deux", "trois", "quatre", "cinq", 
                               "six", "sept", "huit", "neuf", "dix");
      CreateResourceFile(fr, "fr");
      Numbers pt = new Numbers("um", "dois", "três", "quatro", "cinco", 
                               "seis", "sete", "oito", "nove", "dez");
      CreateResourceFile(pt, "pt"); 
      Numbers ru = new Numbers("один", "два", "три", "четыре", "пять", 
                               "шесть", "семь", "восемь", "девять", "десять");                                                       
      CreateResourceFile(ru, "ru");
   }

   public static void CreateResourceFile(Numbers n, string lang)
   {
      string filename = @".\NumberResources" + 
                        (lang != "en" ? "." + lang : "" ) +
                        ".resx";
      ResXResourceWriter rr = new ResXResourceWriter(filename);
      rr.AddResource("Numbers", n);
      rr.Generate();
      rr.Close();    
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:33,代码来源:ResourceManager.GetObject

示例6: Main

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

[assembly:NeutralResourcesLanguageAttribute("en-US")]

public class Example
{
   static string[] cultureNames = { "fr-FR", "pt-BR", "ru-RU" };
   
   public static void Main()
   {
      // Make any non-default culture the current culture.
      Random rnd = new Random();
      CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureNames[rnd.Next(0, cultureNames.Length)]);
      Thread.CurrentThread.CurrentUICulture = culture;
      Console.WriteLine("The current culture is {0}\n", CultureInfo.CurrentUICulture.Name);
      CultureInfo enCulture = CultureInfo.CreateSpecificCulture("en-US"); 

      ResourceManager rm = new ResourceManager(typeof(NumberResources));
      Numbers numbers = (Numbers) rm.GetObject("Numbers");
      Numbers numbersEn = (Numbers) rm.GetObject("Numbers", enCulture);
      Console.WriteLine("{0} --> {1}", numbers.One, numbersEn.One); 
      Console.WriteLine("{0} --> {1}", numbers.Three, numbersEn.Three); 
      Console.WriteLine("{0} --> {1}", numbers.Five, numbersEn.Five); 
      Console.WriteLine("{0} --> {1}", numbers.Seven, numbersEn.Seven); 
      Console.WriteLine("{0} --> {1}\n", numbers.Nine, numbersEn.Nine); 
   }
}

internal class NumberResources
{
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:35,代码来源:ResourceManager.GetObject

输出:

The current culture is pt-BR

um --> one
três --> three
cinco --> five
sete --> seven
nove --> nine


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