本文整理汇总了C#中System.Resources.ResourceReader类的典型用法代码示例。如果您正苦于以下问题:C# ResourceReader类的具体用法?C# ResourceReader怎么用?C# ResourceReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResourceReader类属于System.Resources命名空间,在下文中一共展示了ResourceReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:JoseCasimiro44,项目名称:RulesUtils,代码行数:26,代码来源:ResourcesMustBeReferencedRule.cs
示例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;
}
开发者ID:Small-Basic-French,项目名称:SbTranslationHelper,代码行数:38,代码来源:TranslationReader.cs
示例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;
}
开发者ID:Epikem,项目名称:EpikemMacro1,代码行数:26,代码来源:SkinBamlResolver.cs
示例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);
}
}
开发者ID:canneljls,项目名称:JLSAutoCode,代码行数:34,代码来源:ResourceHelper.cs
示例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;
}
开发者ID:KenMacD,项目名称:NETDeob,代码行数:26,代码来源:Unpacker.cs
示例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();
}
}
开发者ID:ovuncgursoy,项目名称:SisoDb-Provider,代码行数:27,代码来源:SqlStatementsBase.cs
示例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;
}
开发者ID:RookieOne,项目名称:GreekFire,代码行数:28,代码来源:ResourceDictionaryLoader.cs
示例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}");
}
}
}
开发者ID:rdterner,项目名称:OmniXAML,代码行数:28,代码来源:XamlSnippetProvider.cs
示例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;
}
开发者ID:ALyman,项目名称:ILSpy,代码行数:25,代码来源:TestRunner.cs
示例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);
}
}
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:28,代码来源:ResourceReaderUnitTest.cs
示例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;
}
开发者ID:easel,项目名称:autopatch,代码行数:38,代码来源:DatabaseType.cs
示例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);
}
开发者ID:rickeygalloway,项目名称:Test,代码行数:29,代码来源:ScriptLoader.cs
示例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);
}
}
开发者ID:lockflatboy,项目名称:SteamPatch-BO3-BETA,代码行数:32,代码来源:frmMain.cs
示例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);
}
开发者ID:sgtnasty,项目名称:battle,代码行数:29,代码来源:NewCharacterWindow.cs
示例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;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:RuntimeResourceSet.cs
示例16: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
Assembly thisAssembly = Assembly.GetExecutingAssembly();
string[] test = Assembly.GetExecutingAssembly().GetManifestResourceNames();
foreach (string file in test)
{
Stream rgbxml = thisAssembly.GetManifestResourceStream(
file);
try
{
ResourceReader res = new ResourceReader(rgbxml);
IDictionaryEnumerator dict = res.GetEnumerator();
while (dict.MoveNext())
{
Console.WriteLine(" {0}: '{1}' (Type {2})",
dict.Key, dict.Value, dict.Value.GetType().Name);
if (dict.Key.ToString().EndsWith(".ToolTip") || dict.Key.ToString().EndsWith(".Text") || dict.Key.ToString().EndsWith("HeaderText") || dict.Key.ToString().EndsWith("ToolTipText"))
{
dataGridView1.Rows.Add();
dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colFile.Index].Value = System.IO.Path.GetFileName(file);
dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colInternal.Index].Value = dict.Key.ToString();
dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colEnglish.Index].Value = dict.Value.ToString();
dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[colOtherLang.Index].Value = dict.Value.ToString();
}
}
} catch {}
}
}
开发者ID:RodrigoVarasLopez,项目名称:ardupilot-mega,代码行数:34,代码来源:ResEdit.cs
示例17: Constructor_IResourceReader
public void Constructor_IResourceReader ()
{
ResourceReader r = new ResourceReader (MonoTests.System.Resources.ResourceReaderTest.m_ResourceFile);
ConstructorInfo ci = typeof (ResourceSet).GetConstructor (new Type [1] { typeof (IResourceReader) });
ci.Invoke (new object [1] { r });
// works - i.e. no LinkDemand
}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:7,代码来源:ResourceSetCas.cs
示例18: RuntimeResourceSet
internal RuntimeResourceSet(String fileName) : base(false)
{
BCLDebug.Log("RESMGRFILEFORMAT", "RuntimeResourceSet .ctor(String)");
_resCache = new Dictionary<String, ResourceLocator>(FastResourceComparer.Default);
Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
_defaultReader = new ResourceReader(stream, _resCache);
Reader = _defaultReader;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:8,代码来源:runtimeresourceset.cs
示例19: GenerateCode
public void GenerateCode(FileProjectItem item, CustomToolContext context)
{
/*context.GenerateCodeDomAsync(item, context.GetOutputFileName(item, ".Designer"),
delegate {
return GenerateCodeDom();
});*/
string inputFilePath = item.FileName;
// Ensure that the generated code will not conflict with an
// existing class.
if (context.Project != null) {
IProjectContent pc = ParserService.GetProjectContent(context.Project);
if (pc != null) {
IClass existingClass = pc.GetClass(context.OutputNamespace + "." + StronglyTypedResourceBuilder.VerifyResourceName(Path.GetFileNameWithoutExtension(inputFilePath), pc.Language.CodeDomProvider), 0);
if (existingClass != null) {
if (!IsGeneratedResourceClass(existingClass)) {
context.MessageView.AppendLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, ResourceService.GetString("ResourceEditor.ResourceCodeGeneratorTool.ClassConflict"), inputFilePath, existingClass.FullyQualifiedName));
return;
}
}
}
}
IResourceReader reader;
if (string.Equals(Path.GetExtension(inputFilePath), ".resx", StringComparison.OrdinalIgnoreCase)) {
reader = new ResXResourceReader(inputFilePath);
((ResXResourceReader)reader).BasePath = Path.GetDirectoryName(inputFilePath);
} else {
reader = new ResourceReader(inputFilePath);
}
Hashtable resources = new Hashtable();
foreach (DictionaryEntry de in reader) {
resources.Add(de.Key, de.Value);
}
string[] unmatchable = null;
string generatedCodeNamespace = context.OutputNamespace;
context.WriteCodeDomToFile(
item,
context.GetOutputFileName(item, ".Designer"),
StronglyTypedResourceBuilder.Create(
resources, // resourceList
Path.GetFileNameWithoutExtension(inputFilePath), // baseName
generatedCodeNamespace, // generatedCodeNamespace
context.OutputNamespace, // resourcesNamespace
context.Project.LanguageProperties.CodeDomProvider, // codeProvider
createInternalClass, // internal class
out unmatchable
));
foreach (string s in unmatchable) {
context.MessageView.AppendLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, ResourceService.GetString("ResourceEditor.ResourceCodeGeneratorTool.CouldNotGenerateResourceProperty"), s));
}
}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:57,代码来源:ResourceCodeGeneratorTool.cs
示例20: ConstructorString
public void ConstructorString ()
{
if (!File.Exists(m_ResourceFile)) {
Fail ("Resource file is not where it should be:" + Path.Combine (Directory.GetCurrentDirectory(), m_ResourceFile));
}
ResourceReader r = new ResourceReader(m_ResourceFile);
AssertNotNull ("ResourceReader", r);
r.Close();
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:9,代码来源:ResourceReaderTest.cs
注:本文中的System.Resources.ResourceReader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论