• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ResourceReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1:

// Instantiate a standalone .resources file from its filename.
var rr1 = new System.Resources.ResourceReader("Resources1.resources");

// Instantiate a standalone .resources file from a stream.
var fs = new System.IO.FileStream(@".\Resources2.resources",
                                  System.IO.FileMode.Open);
var rr2 = new System.Resources.ResourceReader(fs);
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:7,代码来源:ResourceReader


示例2:

System.Reflection.Assembly assem = 
             System.Reflection.Assembly.LoadFrom(@".\MyLibrary.dll"); 
System.IO.Stream fs = 
             assem.GetManifestResourceStream("MyCompany.LibraryResources.resources");
var rr = new System.Resources.ResourceReader(fs);
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:5,代码来源:ResourceReader


示例3: Main

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

public class Example
{
   public static void Main()
   {
      Console.WriteLine("Resources in ApplicationResources.resources:");
      ResourceReader res = new ResourceReader(@".\ApplicationResources.resources");
      IDictionaryEnumerator dict = res.GetEnumerator();
      while (dict.MoveNext())
         Console.WriteLine("   {0}: '{1}' (Type {2})", 
                           dict.Key, dict.Value, dict.Value.GetType().Name);
      res.Close();
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:18,代码来源:ResourceReader

输出:

Resources in ApplicationResources.resources:
Label3: '"Last Name:"' (Type String)
Label2: '"Middle Name:"' (Type String)
Label1: '"First Name:"' (Type String)
Label7: '"State:"' (Type String)
Label6: '"City:"' (Type String)
Label5: '"Street Address:"' (Type String)
Label4: '"SSN:"' (Type String)
Label9: '"Home Phone:"' (Type String)
Label8: '"Zip Code:"' (Type String)
Title: '"Contact Information"' (Type String)
Label12: '"Other Phone:"' (Type String)
Label13: '"Fax:"' (Type String)
Label10: '"Business Phone:"' (Type String)
Label11: '"Mobile Phone:"' (Type String)
Label14: '"Email Address:"' (Type String)
Label15: '"Alternate Email Address:"' (Type String)


示例4: DateTimeTZI

//引入命名空间
using System;

[Serializable] public struct DateTimeTZI
{
  DateTime Date;
  TimeZoneInfo TimeZone;
   
  public DateTimeTZI(DateTime date, TimeZoneInfo tz)
  {
     this.Date = date;
     this.TimeZone = tz;
  }

   public override string ToString()
   {
     return String.Format("{0:dd/MM/yyyy hh:mm:ss tt} {1}", 
                          Date, TimeZone.StandardName);
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:20,代码来源:ResourceReader


示例5: Main

//引入命名空间
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Resources;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

public class Example
{
   public static void Main()
   {
      // Bitmap as stream.
      MemoryStream bitmapStream = new MemoryStream();
      Bitmap bmp = new Bitmap(@".\ContactsIcon.jpg");
      bmp.Save(bitmapStream, ImageFormat.Jpeg);
          
      // Define resources to be written.
      using (ResourceWriter rw = new ResourceWriter(@".\ContactResources.resources"))
      {
         rw.AddResource("Title", "Contact List");
         rw.AddResource("NColumns", 5);         
         rw.AddResource("Icon", bitmapStream);         
         rw.AddResource("Header1", "Name");
         rw.AddResource("Header2", "City");
         rw.AddResource("Header3", "State");  
         rw.AddResource("VersionDate", new DateTimeTZI(
                        new DateTime(2012, 5, 18),  
                        TimeZoneInfo.Local));
         rw.AddResource("ClientVersion", true);
         rw.Generate();
      }
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:35,代码来源:ResourceReader


示例6: Main

//引入命名空间
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Resources;
using System.Runtime.Serialization.Formatters.Binary;

public class Example
{
   public static void Main()
   {
      ResourceReader rdr = new ResourceReader(@".\ContactResources.resources");  
      IDictionaryEnumerator dict = rdr.GetEnumerator();
      while (dict.MoveNext()) {
         Console.WriteLine("Resource Name: {0}", dict.Key);
         try {
            Console.WriteLine("   Value: {0}", dict.Value);
         }
         catch (FileNotFoundException) {
            Console.WriteLine("   Exception: A file cannot be found.");
            DisplayResourceInfo(rdr, (string) dict.Key, false);
         }
         catch (FormatException) {
            Console.WriteLine("   Exception: Corrupted data.");
            DisplayResourceInfo(rdr, (string) dict.Key, true);
         }
         catch (TypeLoadException) {
            Console.WriteLine("   Exception: Cannot load the data type.");
            DisplayResourceInfo(rdr, (string) dict.Key, false);   
         }
      } 
   }

   private static void DisplayResourceInfo(ResourceReader rr, 
                                   string key, bool loaded)
   {                                
      string dataType = null;
      byte[] data = null;
      rr.GetResourceData(key, out dataType, out data);
            
      // Display the data type.
      Console.WriteLine("   Data Type: {0}", dataType);
      // Display the bytes that form the available data.      
      Console.Write("   Data: ");
      int lines = 0;
      foreach (var dataItem in data) {
         lines++;
         Console.Write("{0:X2} ", dataItem);
         if (lines % 25 == 0)
            Console.Write("\n         ");
      }
      Console.WriteLine();
      // Try to recreate current state of  data.
      // Do: Bitmap, DateTimeTZI
      switch (dataType) 
      {  
         // Handle internally serialized string data (ResourceTypeCode members).
         case "ResourceTypeCode.String":
            BinaryReader reader = new BinaryReader(new MemoryStream(data));
            string binData = reader.ReadString();
            Console.WriteLine("   Recreated Value: {0}", binData);
            break;
         case "ResourceTypeCode.Int32":
            Console.WriteLine("   Recreated Value: {0}", 
                              BitConverter.ToInt32(data, 0));
            break;
         case "ResourceTypeCode.Boolean":
            Console.WriteLine("   Recreated Value: {0}", 
                              BitConverter.ToBoolean(data, 0));
            break;
         // .jpeg image stored as a stream.
         case "ResourceTypeCode.Stream":  
            const int OFFSET = 4;
            int size = BitConverter.ToInt32(data, 0);
            Bitmap value1 = new Bitmap(new MemoryStream(data, OFFSET, size));
            Console.WriteLine("   Recreated Value: {0}", value1); 
            break;
         // Our only other type is DateTimeTZI.
         default:
            // No point in deserializing data if the type is unavailable.
            if (dataType.Contains("DateTimeTZI") && loaded) { 
               BinaryFormatter binFmt = new BinaryFormatter();
               object value2 = binFmt.Deserialize(new MemoryStream(data));
               Console.WriteLine("   Recreated Value: {0}", value2);
            }    
            break;
      }
      Console.WriteLine();
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:91,代码来源:ResourceReader



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ResourceSet类代码示例发布时间:2022-05-24
下一篇:
C# ResourceManager类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap