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


C# ResXResourceReader.BasePath属性代码示例

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


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

示例1: Main

//引入命名空间
using System;
using System.Collections;
using System.ComponentModel.Design;
using System.Drawing;
using System.Reflection;
using System.Resources;

public class Example
{
   public static void Main()
   {
      CreateXMLResourceFile();
      
      // Read the resources in the XML resource file.
      ResXResourceReader resx = new ResXResourceReader("DogBreeds.resx"); 
      Console.WriteLine("Default Base Path: '{0}'", resx.BasePath);
      resx.BasePath = @"C:\Data\";
      Console.WriteLine("Current Base Path: '{0}'\n", resx.BasePath); 
      resx.UseResXDataNodes = true;

      IDictionaryEnumerator dict = resx.GetEnumerator();
      AssemblyName[] assemblyNames = { new AssemblyName(typeof(Bitmap).Assembly.FullName) };
      while (dict.MoveNext()) {
         ResXDataNode node = (ResXDataNode) dict.Value;
         if (node.FileRef != null) {
            object image = node.GetValue(assemblyNames);
            Console.WriteLine("{0}: {1} from {2}", dict.Key, 
                              image.GetType().Name, node.FileRef.FileName);
         }
         else {
            Console.WriteLine("{0}: {1}", node.Name, node.GetValue((ITypeResolutionService) null));
         }   
      }   
   }

   private static void CreateXMLResourceFile()
   {
      // Define an array of ResXFileRef objects for images.
      String typeName = String.Format("{0}, {1}", typeof(Bitmap).FullName, 
                                      typeof(Bitmap).Assembly.FullName);
      ResXFileRef[] imageRefs =
         { new ResXFileRef(@"images\Akita.jpg", typeName),
           new ResXFileRef(@"images\Dalmatian.jpg", typeName),
           new ResXFileRef(@"images\Husky.jpg", typeName),
           new ResXFileRef(@"images\GreatPyrenees.jpg", typeName),
           new ResXFileRef(@"images\Malamute.jpg", typeName),
           new ResXFileRef(@"images\newfoundland.jpg", typeName),
           new ResXFileRef(@"images\Rottweiler.jpg", typeName) 
         };
      
      using (ResXResourceWriter resx = new ResXResourceWriter(@".\DogBreeds.resx")) {
         // Add each ResXFileRef object to the resource file.
         foreach (var imageRef in imageRefs) {
            // Form resource name from name of image.
            String name = imageRef.FileName;
            name = name.Substring(name.IndexOf(@"\") + 1);
            name = name.Substring(0, name.IndexOf("."));
            ResXDataNode node = new ResXDataNode(name, imageRef); 
            resx.AddResource(node);
         }
         resx.AddResource("CreatedBy", typeof(Example).Assembly.FullName);
      }   
   }
}
开发者ID:.NET开发者,项目名称:System.Resources,代码行数:65,代码来源:ResXResourceReader.BasePath

输出:

Default Base Path: ''
Current Base Path: 'C:\Data\'

Akita: Bitmap from C:\Data\images\Akita.jpg
Dalmatian: Bitmap from C:\Data\images\Dalmatian.jpg
Husky: Bitmap from C:\Data\images\Husky.jpg
GreatPyrenees: Bitmap from C:\Data\images\GreatPyrenees.jpg
Malamute: Bitmap from C:\Data\images\Malamute.jpg
newfoundland: Bitmap from C:\Data\images\newfoundland.jpg
Rottweiler: Bitmap from C:\Data\images\Rottweiler.jpg
CreatedBy: BasePathEx1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null


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