本文整理汇总了C#中System.Resources.ResXResourceReader.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# ResXResourceReader.GetEnumerator方法的具体用法?C# ResXResourceReader.GetEnumerator怎么用?C# ResXResourceReader.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Resources.ResXResourceReader
的用法示例。
在下文中一共展示了ResXResourceReader.GetEnumerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getBMPFiles
public static void getBMPFiles(string resxFile)
{
// Create a Resource Reader
ResXResourceReader rsxr = new ResXResourceReader(resxFile);
// Create a enumerator
IDictionaryEnumerator id = rsxr.GetEnumerator();
int i = 0;
foreach (DictionaryEntry d in rsxr)
{
Bitmap b = d.Value as Bitmap;
if (b != null)
{
b.Save(resxFile + "__" + i.ToString() + ".bmp");
i++;
}
}
//Close the reader.
rsxr.Close();
}
示例2: GetCustomerCredentials
/// <summary>
/// To Get the user credentials from Customer Resource file
/// </summary>
/// Authour: Pradeep
/// <param name="custType">Type of the customer</param>
/// <returns>returns an array with UserName and Password</returns>
/// Created Date: 22-Dec-2011
/// Modified Date: 22-Dec-2011
/// Modification Comments
public static string[] GetCustomerCredentials(string custType)
{
try
{
Stream stream = new System.IO.FileStream(ResFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
var resFileData = new ResXResourceReader(stream);
IDictionaryEnumerator resFileDataDict = resFileData.GetEnumerator();
var customerCreds = new string[2];
while (resFileDataDict.MoveNext())
{
if (custType.ToString(CultureInfo.InvariantCulture) == resFileDataDict.Key.ToString())
{
string temp = resFileDataDict.Value.ToString();
customerCreds = temp.Split(';');
break;
}
}
resFileData.Close();
stream.Dispose();
return customerCreds;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return null;
}
}
示例3: LoadResources
void LoadResources(ResXResourceReader resxReader)
{
IDictionaryEnumerator enumerator = resxReader.GetEnumerator ();
while (enumerator.MoveNext ()) {
Resources.Add (enumerator.Value as ResXDataNode);
}
}
示例4: UpdateResourceFile
public static void UpdateResourceFile(Hashtable data, string path, TranslatorForm form)
{
form.TextOutput = "Writing " + path + "...";
Hashtable resourceEntries = new Hashtable();
bool check = false;
//Get existing resources
ResXResourceReader reader = new ResXResourceReader(path);
if (reader != null)
{
IDictionaryEnumerator id = reader.GetEnumerator();
foreach (DictionaryEntry d in reader)
{
if (d.Value == null)
resourceEntries.Add(d.Key.ToString(), "");
else
resourceEntries.Add(d.Key.ToString(), d.Value.ToString());
}
reader.Close();
}
//Modify resources here...
foreach (String key in data.Keys)
{
if (!resourceEntries.ContainsKey(key))
{
String value = data[key].ToString();
if (value == null) value = "";
resourceEntries.Add(key, value);
}
}
//Write the combined resource file
ResXResourceWriter resourceWriter = new ResXResourceWriter(path);
foreach (String key in resourceEntries.Keys)
{
resourceWriter.AddResource(key, resourceEntries[key]);
}
resourceWriter.Generate();
resourceWriter.Close();
//Check if entered correctly
reader = new ResXResourceReader(path);
if (reader != null)
{
foreach (DictionaryEntry d in reader)
foreach (String key in resourceEntries.Keys)
{
if ((string) d.Key == key && (string) d.Value == (string) resourceEntries[key]) check = true;
}
reader.Close();
}
if (check) form.TextOutput = path + " written successfully";
else form.TextOutput = path + " not written !!";
}
示例5: ResxToResourceStringDictionary
public List<ResxStringResource> ResxToResourceStringDictionary(TextReader resxFileContent)
{
try
{
var result = new List<ResxStringResource>();
// Reading comments: http://msdn.microsoft.com/en-us/library/system.resources.resxdatanode.aspx
using (var reader = new ResXResourceReader(resxFileContent))
{
reader.UseResXDataNodes = true;
var dict = reader.GetEnumerator();
while (dict.MoveNext())
{
var node = (ResXDataNode)dict.Value;
result.Add(new ResxStringResource()
{
Name = node.Name,
Value = (string)node.GetValue((ITypeResolutionService)null),
Comment = node.Comment
});
}
}
return result;
}
catch (Exception ex)
{
Trace.TraceError(ex.ToString());
}
return null;
}
开发者ID:transformersprimeabcxyz,项目名称:ResourceFirstTranslations,代码行数:34,代码来源:ResxStringResourceReader.cs
示例6: Test
public void Test ()
{
Thread.CurrentThread.CurrentCulture =
Thread.CurrentThread.CurrentUICulture = new CultureInfo ("de-DE");
ResXResourceWriter w = new ResXResourceWriter (fileName);
w.AddResource ("point", new Point (42, 43));
w.Generate ();
w.Close ();
int count = 0;
ResXResourceReader r = new ResXResourceReader (fileName);
IDictionaryEnumerator e = r.GetEnumerator ();
while (e.MoveNext ()) {
if ((string) e.Key == "point") {
Assert.AreEqual (typeof (Point), e.Value.GetType (), "#1");
Point p = (Point) e.Value;
Assert.AreEqual (42, p.X, "#2");
Assert.AreEqual (43, p.Y, "#3");
count++;
}
}
r.Close ();
Assert.AreEqual (1, count, "#100");
}
示例7: ResXConfigHandler
public ResXConfigHandler(string filePath)
{
// Create a ResXResourceReader for the file items.resx.
rsxr = new ResXResourceReader(filePath);
// Create an IDictionaryEnumerator to iterate through the resources.
rsxr.GetEnumerator();
}
示例8: Run
public override void Run()
{
// Here an example that shows how to access the current text document:
ITextEditorProvider tecp = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorProvider;
if (tecp == null) {
// active content is not a text editor control
return;
}
// Get the active text area from the control:
ITextEditor textEditor = tecp.TextEditor;
if (textEditor.SelectionLength == 0)
return;
// get the selected text:
string text = textEditor.SelectedText;
string sdSrcPath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location),
"../../../..");
string resxFile = Path.Combine(sdSrcPath, "../data/Resources/StringResources.resx");
using (ResXResourceReader r = new ResXResourceReader(resxFile)) {
IDictionaryEnumerator en = r.GetEnumerator();
// Goes through the enumerator, printing out the key and value pairs.
while (en.MoveNext()) {
if (object.Equals(en.Value, text)) {
SetText(textEditor, en.Key.ToString(), text);
return;
}
}
}
string resourceName = MessageService.ShowInputBox("Add Resource", "Please enter the name for the new resource.\n" +
"This should be a namespace-like construct, please see what the names of resources in the same component are.", PropertyService.Get("ResourceToolLastResourceName"));
if (resourceName == null || resourceName.Length == 0) return;
PropertyService.Set("ResourceToolLastResourceName", resourceName);
string purpose = MessageService.ShowInputBox("Add Resource", "Enter resource purpose (may be empty)", "");
if (purpose == null) return;
SetText(textEditor, resourceName, text);
string path = Path.GetFullPath(Path.Combine(sdSrcPath, "Tools/StringResourceTool/bin/Debug"));
ProcessStartInfo info = new ProcessStartInfo(path + "\\StringResourceTool.exe",
"\"" + resourceName + "\" "
+ "\"" + text + "\" "
+ "\"" + purpose + "\"");
info.WorkingDirectory = path;
try {
Process.Start(info);
} catch (Exception ex) {
MessageService.ShowException(ex, "Error starting " + info.FileName);
}
}
示例9: GetNodeFromResXReader
protected ResXDataNode GetNodeFromResXReader (string contents)
{
StringReader sr = new StringReader (contents);
using (ResXResourceReader reader = new ResXResourceReader (sr)) {
reader.UseResXDataNodes = true;
IDictionaryEnumerator enumerator = reader.GetEnumerator ();
enumerator.MoveNext ();
return (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value;
}
}
示例10: KeyExists
public bool KeyExists(FileInfo fileInfo, string key)
{
using (reader)
{
reader = new ResXResourceReader(fileInfo.FullName);
var enumerator = reader.GetEnumerator();
foreach (DictionaryEntry d in reader)
if (String.Equals(d.Key.ToString(), key, StringComparison.CurrentCultureIgnoreCase)) return true;
}
return false;
}
示例11: ctor
[Test] // ctor (Stream)
public void Constructor1_Stream_InvalidContent ()
{
MemoryStream ms = new MemoryStream ();
ms.WriteByte (byte.MaxValue);
ms.Position = 0;
ResXResourceReader r = new ResXResourceReader (ms);
try {
r.GetEnumerator ();
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Invalid ResX input
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNotNull (ex.Message, "#3");
Assert.IsNull (ex.ParamName, "#4");
Assert.IsNotNull (ex.InnerException, "#5");
}
}
示例12: ImportResxFile
public void ImportResxFile(string resxPath, string rootPath, string defaultCulture = "en-US", bool globalResource = false)
{
using (var resxFile = new ResXResourceReader(resxPath))
{
var dictEnumerator = resxFile.GetEnumerator();
while (dictEnumerator.MoveNext())
{
var record = new ResourceRecord(_connectionString)
{
Page = GetPagePath(resxPath, rootPath, globalResource),
CultureCode = GetCulture(resxPath, defaultCulture),
Key = dictEnumerator.Key.ToString(),
Value = dictEnumerator.Value.ToString()
};
record.Save();
Console.WriteLine(string.Format("Saved record for page {0}, key: {1} value: {2}", record.Page, record.Key, record.Value));
}
}
}
示例13: GetRes
public static string GetRes(string viewName, string resName)
{
var culture = Thread.CurrentThread.CurrentCulture;
var fileName = viewName + culture.Parent.Name + ".resx";
var folderName = HttpContext.Current.Server.MapPath("~/LanguageResources/");
var rr = new System.Resources.ResXResourceReader(folderName + fileName);
var resources = rr.GetEnumerator();
while (resources.MoveNext())
{
if (resources.Key.ToString() == resName)
{
return resources.Value.ToString();
}
}
return "";
}
示例14: ProcessFile
public override void ProcessFile(string filePath, Dictionary<string, LocalizableEntity> map)
{
Logger.LogFormat("Processing file {0}", filePath);
try
{
using (var reader = new ResXResourceReader(filePath))
{
var dict = reader.GetEnumerator();
while (dict.MoveNext())
map.Add(dict.Key.ToString(), GetLocalizableProperty(filePath, dict.Key.ToString(), dict.Value.ToString()));
}
}
catch (Exception ex)
{
Logger.LogFormat("Error ({0})", filePath);
throw ex;
}
}
示例15: GenerateJavaScriptResxFile
private static void GenerateJavaScriptResxFile(string resxFilePath, string outDir, string vsdocOutDir, string resourceNamespace, string registerNamespace, bool generateVsDoc)
{
StringBuilder resourceSb = new StringBuilder();
StringBuilder vsdocSb = new StringBuilder();
using (ResXResourceReader rr = new ResXResourceReader(resxFilePath))
{
IDictionaryEnumerator di = rr.GetEnumerator();
foreach (DictionaryEntry de in rr)
{
string key = de.Key as string;
string value = de.Value as string;
if (_ReservedWords.Contains(key))
{
key = "_" + key;
}
resourceSb.AppendFormat("'{0}': '{1}',", key, value.Replace("'", "\\'").Replace(Environment.NewLine, String.Empty));
if (generateVsDoc)
{
vsdocSb.AppendFormat("'{0}': '',", key);
}
}
}
if (!String.IsNullOrWhiteSpace(registerNamespace))
{
registerNamespace = "\t" + registerNamespace + " = {};";
}
var resourceFileContents = _JavascriptFileTemplate.Replace("#KEYS#", resourceSb.ToString().TrimEnd(',')).Replace("#REGISTERNAMESPACE#", registerNamespace).Replace("#NAMESPACE#", resourceNamespace);
File.WriteAllText(outDir, resourceFileContents);
if (generateVsDoc)
{
var vsdocFileContents = _VsDocFileTemplate.Replace("#KEYS#", vsdocSb.ToString().TrimEnd(',')).Replace("#REGISTERNAMESPACE#", registerNamespace).Replace("#NAMESPACE#", resourceNamespace);
File.WriteAllText(vsdocOutDir, vsdocFileContents);
}
}