本文整理汇总了C#中System.Resources.ResourceSet.All方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceSet.All方法的具体用法?C# ResourceSet.All怎么用?C# ResourceSet.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Resources.ResourceSet
的用法示例。
在下文中一共展示了ResourceSet.All方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decompile
void Decompile()
{
Stream s = resource.GetResourceStream();
s.Position = 0;
if (resource.Name.EndsWith(".g.resources", StringComparison.OrdinalIgnoreCase))
{
IEnumerable<DictionaryEntry> rs = null;
try { rs = new ResourceSet(s).Cast<DictionaryEntry>(); }
catch (ArgumentException) { }
if (rs != null && rs.All(e => e.Value is Stream))
{
foreach (var pair in rs)
{
Stream entryStream = (Stream)pair.Value;
byte[] d = new byte[entryStream.Length];
entryStream.Position = 0;
if (pair.Key.ToString().EndsWith(".baml", StringComparison.OrdinalIgnoreCase))
{
MemoryStream ms = new MemoryStream();
entryStream.CopyTo(ms);
// TODO implement extension point
// var decompiler = Baml.BamlResourceEntryNode.CreateBamlDecompilerInAppDomain(ref bamlDecompilerAppDomain, assembly.FileName);
// string xaml = null;
// try {
// xaml = decompiler.DecompileBaml(ms, assembly.FileName, new ConnectMethodDecompiler(assembly), new AssemblyResolver(assembly));
// }
// catch (XamlXmlWriterException) { } // ignore XAML writer exceptions
// if (xaml != null) {
// File.WriteAllText(Path.Combine(options.SaveAsProjectDirectory, Path.ChangeExtension(fileName, ".xaml")), xaml);
// yield return Tuple.Create("Page", Path.ChangeExtension(fileName, ".xaml"));
// continue;
// }
}
else
{
entryStream.Read(d, 0, (int)entryStream.Length);
}
string tmp = Path.GetTempFileName();
File.WriteAllBytes(tmp, d);
Entries.Add(pair.Key.ToString(), tmp);
}
}
}
}
示例2: WriteResourceFilesInProject
IEnumerable<Tuple<string, string>> WriteResourceFilesInProject(LoadedAssembly assembly, DecompilationOptions options, HashSet<string> directories)
{
//AppDomain bamlDecompilerAppDomain = null;
//try {
foreach (EmbeddedResource r in assembly.AssemblyDefinition.MainModule.Resources.OfType<EmbeddedResource>()) {
string fileName;
Stream s = r.GetResourceStream();
s.Position = 0;
if (r.Name.EndsWith(".g.resources", StringComparison.OrdinalIgnoreCase)) {
IEnumerable<DictionaryEntry> rs = null;
try {
rs = new ResourceSet(s).Cast<DictionaryEntry>();
}
catch (ArgumentException) {
}
if (rs != null && rs.All(e => e.Value is Stream)) {
foreach (var pair in rs) {
fileName = Path.Combine(((string)pair.Key).Split('/').Select(p => TextView.DecompilerTextView.CleanUpName(p)).ToArray());
string dirName = Path.GetDirectoryName(fileName);
if (!string.IsNullOrEmpty(dirName) && directories.Add(dirName)) {
Directory.CreateDirectory(Path.Combine(options.SaveAsProjectDirectory, dirName));
}
Stream entryStream = (Stream)pair.Value;
entryStream.Position = 0;
if (fileName.EndsWith(".baml", StringComparison.OrdinalIgnoreCase)) {
MemoryStream ms = new MemoryStream();
entryStream.CopyTo(ms);
// TODO implement extension point
// var decompiler = Baml.BamlResourceEntryNode.CreateBamlDecompilerInAppDomain(ref bamlDecompilerAppDomain, assembly.FileName);
// string xaml = null;
// try {
// xaml = decompiler.DecompileBaml(ms, assembly.FileName, new ConnectMethodDecompiler(assembly), new AssemblyResolver(assembly));
// }
// catch (XamlXmlWriterException) { } // ignore XAML writer exceptions
// if (xaml != null) {
// File.WriteAllText(Path.Combine(options.SaveAsProjectDirectory, Path.ChangeExtension(fileName, ".xaml")), xaml);
// yield return Tuple.Create("Page", Path.ChangeExtension(fileName, ".xaml"));
// continue;
// }
}
using (FileStream fs = new FileStream(Path.Combine(options.SaveAsProjectDirectory, fileName), FileMode.Create, FileAccess.Write)) {
entryStream.CopyTo(fs);
}
yield return Tuple.Create("Resource", fileName);
}
continue;
}
}
fileName = GetFileNameForResource(r.Name, directories);
using (FileStream fs = new FileStream(Path.Combine(options.SaveAsProjectDirectory, fileName), FileMode.Create, FileAccess.Write)) {
s.CopyTo(fs);
}
yield return Tuple.Create("EmbeddedResource", fileName);
}
//}
//finally {
// if (bamlDecompilerAppDomain != null)
// AppDomain.Unload(bamlDecompilerAppDomain);
//}
}
示例3: WriteResourceFilesInProject
private IEnumerable<Tuple<string, string>> WriteResourceFilesInProject()
{
foreach (var r in iAsm.ModuleDefinition.Resources.OfType<EmbeddedResource>())
{
string absolutePath;
string relativePath;
Stream s = r.GetResourceStream();
s.Position = 0;
char separator;
if (r.Name.EndsWith(".g.resources", StringComparison.OrdinalIgnoreCase))
{
separator = '/';
IEnumerable<DictionaryEntry> rs = null;
try
{
rs = new ResourceSet(s).Cast<DictionaryEntry>();
}
catch (ArgumentException)
{
}
if (rs != null && rs.All(e => e.Value is Stream))
{
foreach (var pair in rs)
{
GetFilePath((string)pair.Key, separator, out absolutePath, out relativePath);
Stream entryStream = (Stream)pair.Value;
entryStream.Position = 0;
if (relativePath.EndsWith(".baml", StringComparison.OrdinalIgnoreCase))
{
var xdoc = GetXamlDocument(relativePath, entryStream);
if (xdoc != null)
{
xdoc.Save(Path.ChangeExtension(absolutePath, ".xaml"));
yield return Tuple.Create("Page", Path.ChangeExtension(relativePath, ".xaml"));
continue;
}
}
using (FileStream fs = new FileStream(absolutePath, FileMode.Create, FileAccess.Write))
{
entryStream.CopyTo(fs);
}
yield return Tuple.Create("Resource", relativePath);
}
continue;
}
}
else
{
separator = '.';
}
GetFilePath(r.Name, separator, out absolutePath, out relativePath);
var content = relativePath.EndsWith(".resx", StringComparison.InvariantCultureIgnoreCase)
? GetResxContent(r)
: null;
if (content != null)
{
File.WriteAllText(absolutePath, content, Encoding.UTF8);
}
else
{
using (FileStream fs = new FileStream(absolutePath, FileMode.Create, FileAccess.Write))
{
s.CopyTo(fs);
}
}
yield return Tuple.Create("EmbeddedResource", relativePath);
}
}