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


C# ResourceSet.All方法代码示例

本文整理汇总了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);
             }
         }
     }
 }
开发者ID:net-shell,项目名称:quantum-vaginer,代码行数:44,代码来源:ResourceDecompiler.cs

示例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);
			//}
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:60,代码来源:CSharpLanguage.cs

示例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);
                }
            }
开发者ID:DKeeper1523,项目名称:ilspy_yh,代码行数:72,代码来源:CSharpLanguage.cs


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