本文整理汇总了C#中System.Resources.ResourceReader类的典型用法代码示例。如果您正苦于以下问题:C# ResourceReader类的具体用法?C# ResourceReader怎么用?C# ResourceReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResourceReader类属于System.Resources命名空间,在下文中一共展示了ResourceReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Check
public override ProblemCollection Check( Resource resource )
{
using( var stream = new MemoryStream( resource.Data ) )
{
try
{
using( ResourceReader reader = new ResourceReader( stream ) )
{
AssemblyResourceNameHelper nameHelper = AssemblyResourceNameHelper.Get( resource.DefiningModule.ContainingAssembly );
IEnumerable<string> allTextResources = reader.Cast<DictionaryEntry>().Select( e => e.Key.ToString() );
IEnumerable<string> allNotReferencedResources = allTextResources.Where( resourceName => !nameHelper.Contains( resourceName ) );
foreach( var resourceName in allNotReferencedResources )
{
Problems.Add( new Problem( GetResolution( resourceName, resource.Name ), resourceName ) );
}
}
}
catch( Exception )
{
}
}
return Problems;
}
示例2: ReadExecutableFile
/// <summary>
/// Read the translations from an executable file
/// </summary>
public static IEnumerable<TranslationFileValue> ReadExecutableFile(String group, String file)
{
// Load the assembly
Assembly asm = Assembly.LoadFile(file);
// Explore all resources
var resourceNames = asm.GetManifestResourceNames().Where(n => n.EndsWith(".resources"));
foreach (var resName in resourceNames)
{
// Cleanup the name
var cleanResName = resName.Replace(".resources", "");
// Open the stream for String type
using (var stream = asm.GetManifestResourceStream(resName))
{
if (stream != null)
{
using (var reader = new ResourceReader(stream))
{
foreach (DictionaryEntry item in reader)
{
if (!(item.Key is string) && !(item.Value is string))
continue;
TranslationFileValue tData = new TranslationFileValue
{
ReferenceGroup = group,
ReferenceCode = item.Key.ToString(),
Translation = item.Value.ToString()
};
yield return tData;
}
}
}
}
}
yield break;
}
示例3: foreach
List<Stream> ISkinBamlResolver.GetSkinBamlStreams(AssemblyName skinAssemblyName, string bamlResourceName)
{
List<Stream> skinBamlStreams = new List<Stream>();
Assembly skinAssembly = Assembly.Load(skinAssemblyName);
string[] resourcesNames = skinAssembly.GetManifestResourceNames();
foreach (string resourceName in resourcesNames)
{
ManifestResourceInfo resourceInfo = skinAssembly.GetManifestResourceInfo(resourceName);
if (resourceInfo.ResourceLocation != ResourceLocation.ContainedInAnotherAssembly)
{
Stream resourceStream = skinAssembly.GetManifestResourceStream(resourceName);
using (ResourceReader resourceReader = new ResourceReader(resourceStream))
{
foreach (DictionaryEntry entry in resourceReader)
{
if (IsRelevantResource(entry, bamlResourceName))
{
skinBamlStreams.Add(entry.Value as Stream);
}
}
}
}
}
return skinBamlStreams;
}
示例4: ResourceHelper
/// <summary>
/// 默认构造函数
/// </summary>
/// <param name="filepath">资源文件路径</param>
public ResourceHelper(string filepath)
{
this.m_FilePath = filepath;
this.m_Hashtable = new Hashtable();
//如果存在
if (File.Exists(filepath))
{
string tempFile = HConst.TemplatePath + "\\decryptFile.resx";
//解密文件
//System.Net.Security tSecurity = new Security();
//tSecurity.DecryptDES(filepath, tempFile);
File.Copy(filepath, tempFile);
using (ResourceReader ResReader = new ResourceReader(tempFile))
{
IDictionaryEnumerator tDictEnum = ResReader.GetEnumerator();
while (tDictEnum.MoveNext())
{
this.m_Hashtable.Add(tDictEnum.Key, tDictEnum.Value);
}
ResReader.Close();
}
//删除临时文件
File.Delete(tempFile);
}
}
示例5: Phase2
public static bool Phase2()
{
var resName = PhaseParam;
var resReader = new ResourceReader(AsmDef.FindResource(res => res.Name == "app.resources").GetResourceStream());
var en = resReader.GetEnumerator();
byte[] resData = null;
while (en.MoveNext())
{
if (en.Key.ToString() == resName)
resData = en.Value as byte[];
}
if(resData == null)
{
PhaseError = new PhaseError
{
Level = PhaseError.ErrorLevel.Critical,
Message = "Could not read resource data!"
};
}
PhaseParam = resData;
return true;
}
示例6: SqlStatementsBase
protected SqlStatementsBase(Assembly assembly, string resourcePath)
{
Ensure.That(assembly, "assembly").IsNotNull();
Ensure.That(resourcePath, "resourcePath").IsNotNullOrWhiteSpace();
if (!resourcePath.EndsWith(".resources"))
resourcePath = string.Concat(resourcePath, ".resources");
resourcePath = string.Concat(assembly.GetName().Name, ".", resourcePath);
_sqlStrings = new Dictionary<string, string>();
using (var resourceStream = assembly.GetManifestResourceStream(resourcePath))
{
using (var reader = new ResourceReader(resourceStream))
{
var e = reader.GetEnumerator();
while (e.MoveNext())
{
_sqlStrings.Add(e.Key.ToString(), e.Value.ToString());
}
}
if(resourceStream != null)
resourceStream.Close();
}
}
示例7: LoadResourceDictionaries
/// <summary>
/// Loads the resource dictionaries.
/// </summary>
public IResourceDictionaryLoader LoadResourceDictionaries()
{
string assemblyName = Assembly.GetName().Name;
Stream stream = Assembly.GetManifestResourceStream(assemblyName + ".g.resources");
using (var reader = new ResourceReader(stream))
{
foreach (DictionaryEntry entry in reader)
{
var key = (string) entry.Key;
key = key.Replace(".baml", ".xaml");
string uriString = String.Format("pack://application:,,,/{0};Component/{1}", assemblyName, key);
var dictionary = new ResourceDictionary
{
Source = new Uri(uriString)
};
Application.Current.Resources.MergedDictionaries.Add(dictionary);
}
}
return this;
}
示例8: XamlSnippetProvider
public XamlSnippetProvider(Assembly assembly, string resourceIdString)
{
var resourceIds = new[] { resourceIdString };
foreach (var resourceId in resourceIds)
{
try
{
using (var reader = new ResourceReader(assembly.GetManifestResourceStream(resourceId)))
{
var enumerator = reader.GetEnumerator();
while (enumerator.MoveNext())
{
var name = enumerator.Key as string;
var xaml = enumerator.Value as string;
if (name != null && xaml != null)
{
snippets.Add(new Snippet(name, xaml));
}
}
}
}
catch (Exception e)
{
Debug.WriteLine($"Cannot load snippets. Exception: {e}");
}
}
}
示例9: LoadBaml
Stream LoadBaml(Resource res, string name)
{
EmbeddedResource er = res as EmbeddedResource;
if (er != null) {
Stream s = er.GetResourceStream();
s.Position = 0;
ResourceReader reader;
try {
reader = new ResourceReader(s);
}
catch (ArgumentException) {
return null;
}
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) {
if (entry.Key.ToString() == name) {
if (entry.Value is Stream)
return (Stream)entry.Value;
if (entry.Value is byte[])
return new MemoryStream((byte[])entry.Value);
}
}
}
return null;
}
示例10: ReadResource
public static void ReadResource()
{
using (var ms2 = new MemoryStream())
{
using (var rw = GenerateResourceStream(s_dict, ms2))
{
//Rewind to beginning of stream
ms2.Seek(0L, SeekOrigin.Begin);
var reder = new ResourceReader(ms2);
var s_found_list = new List<string>();
foreach (DictionaryEntry entry in reder)
{
string key = (string)entry.Key;
string value = (string)entry.Value;
string found = s_dict[key];
Assert.True(string.Compare(value, found) == 0, "expected: " + value + ", but got : " + found);
s_found_list.Add(key);
}
Assert.True(s_found_list.Count == s_dict.Count);
}
}
}
示例11: DatabaseType
/// <summary> Creates a new <code>DatabaseType</code>.
///
/// </summary>
/// <param name="databaseType">the type of database
/// </param>
public DatabaseType(System.String databaseType)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string resourceName = string.Format("AutopatchNet.{0}.resources", databaseType.ToLower());
System.IO.Stream rs = assembly.GetManifestResourceStream(resourceName);
if (rs == null)
{
throw new System.ArgumentException("Could not find SQL resources file for database '" + databaseType + "'; make sure that there is a '" + databaseType.ToLower() + ".resources' file in package.");
}
try
{
ResourceReader reader = new ResourceReader(rs);
IDictionaryEnumerator en = reader.GetEnumerator();
while(en.MoveNext())
{
string sqlkey = (string)en.Key;
string sql = (string)en.Value;
properties.Add(sqlkey, sql);
}
reader.Close();
}
catch (System.IO.IOException e)
{
throw new System.ArgumentException("Could not read SQL resources file for database '" + databaseType + "'.", e);
}
finally
{
rs.Close();
}
this.databaseType = databaseType;
}
示例12: GetScriptsFromAssembly
public static void GetScriptsFromAssembly()
{
string fileName = AppDomain.CurrentDomain.GetData("FileName") as string;
string resourceFileName = AppDomain.CurrentDomain.GetData("ResourceFileName") as string;
IEnumerable<string> resourceFileNames = AppDomain.CurrentDomain.GetData("ResourceFileNames") as IEnumerable<string>;
var dbScriptsToExecute = new Dictionary<string, string>();
Assembly assembly = Assembly.LoadFile(Path.GetFullPath(fileName));
foreach (string resourceName in assembly.GetManifestResourceNames())
{
if (FindResource(resourceName, resourceFileName, resourceFileNames))
{
using (Stream s = assembly.GetManifestResourceStream(resourceName))
{
// Get scripts from the current component
var reader = new ResourceReader(s);
foreach (DictionaryEntry entry in reader)
{
dbScriptsToExecute.Add(entry.Key.ToString(), entry.Value.ToString());
}
}
}
}
AppDomain.CurrentDomain.SetData("DbScriptsToExecute", dbScriptsToExecute);
}
示例13: FixNow
private void FixNow(string path)
{
try
{
string sound = Path.Combine(path, "zone", "snd");
if (!Directory.Exists(sound))
throw new Exception("リソース(資源)の一部が欠けてるようです。");
sound = Path.Combine(sound, "en");
Directory.CreateDirectory(sound);
Assembly asm = Assembly.GetExecutingAssembly();
Stream resource = asm.GetManifestResourceStream("SteamPatch_BO3_BETA.Properties.Resources.resources");
using (IResourceReader render = new ResourceReader(resource))
{
IDictionaryEnumerator id = render.GetEnumerator();
while (id.MoveNext())
{
byte[] bytes = (byte[])id.Value;
string file = Path.Combine(sound, id.Key.ToString());
File.WriteAllBytes(file, bytes);
}
}
MessageBox.Show("適応しました", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例14: build_page_1
private void build_page_1()
{
TextView tv1 = new TextView ();
try
{
string rez = "Adeptus.Resources.resources";
string key = "mystring1";
string resourceType = "";
byte[] resourceData;
ResourceReader r = new ResourceReader(rez);
r.GetResourceData (key, out resourceType, out resourceData);
r.Close();
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
tv1.Buffer.Text = enc.GetString (resourceData);
}
catch (Exception exp)
{
tv1.Buffer.Text = exp.Message;
}
tv1.WrapMode = WrapMode.Word;
tv1.Editable = false;
this.AppendPage (tv1);
this.SetPageTitle (tv1, "Introduction");
this.SetPageType (tv1, AssistantPageType.Intro);
this.SetPageComplete (tv1, true);
}
示例15: RuntimeResourceSet
internal RuntimeResourceSet(string fileName) : base(false)
{
this._resCache = new Dictionary<string, ResourceLocator>(FastResourceComparer.Default);
Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
this._defaultReader = new ResourceReader(stream, this._resCache);
base.Reader = this._defaultReader;
}