本文整理汇总了C#中System.Resources.ResourceReader.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceReader.Cast方法的具体用法?C# ResourceReader.Cast怎么用?C# ResourceReader.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Resources.ResourceReader
的用法示例。
在下文中一共展示了ResourceReader.Cast方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: LoadChildren
protected override void LoadChildren()
{
EmbeddedResource er = this.Resource as EmbeddedResource;
if (er != null) {
Stream s = er.GetResourceStream();
s.Position = 0;
ResourceReader reader;
try {
reader = new ResourceReader(s);
}
catch (ArgumentException) {
return;
}
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) {
ProcessResourceEntry(entry);
}
}
}
示例3: LoadPieceSetFromResource
/// <summary>
/// Load piece sets from resource
/// </summary>
/// <returns></returns>
public static SortedList<string, PieceSet> LoadPieceSetFromResource()
{
SortedList<string, PieceSet> arrRetVal;
Assembly asm;
string strResName;
string strKeyName;
string strPieceSetName;
string[] arrPart;
Stream streamResource;
ResourceReader resReader;
PieceSet pieceSet;
arrRetVal = new SortedList<string,PieceSet>(64);
asm = typeof(App).Assembly;
strResName = asm.GetName().Name + ".g.resources";
streamResource = asm.GetManifestResourceStream(strResName);
try {
resReader = new System.Resources.ResourceReader(streamResource);
streamResource = null;
using (resReader) {
foreach (DictionaryEntry dictEntry in resReader.Cast<DictionaryEntry>()) {
strKeyName = dictEntry.Key as string;
if (strKeyName != null) {
strKeyName = strKeyName.ToLower();
if (strKeyName.StartsWith("piecesets/") && strKeyName.EndsWith(".baml")) {
arrPart = strKeyName.Split('/');
if (arrPart.Length == 3) {
strPieceSetName = arrPart[1];
if (!arrRetVal.ContainsKey(strPieceSetName)) {
pieceSet = new PieceSetStandard(strPieceSetName, strPieceSetName);
arrRetVal.Add(strPieceSetName, pieceSet);
}
}
}
}
}
}
} finally {
if (streamResource != null) {
streamResource.Dispose();
}
}
return(arrRetVal);
}
示例4: LoadChildren
protected override void LoadChildren()
{
EmbeddedResource er = this.Resource as EmbeddedResource;
if (er != null) {
Stream s = er.GetResourceStream();
s.Position = 0;
ResourceReader reader;
try {
reader = new ResourceReader(s);
}
catch (ArgumentException) {
return;
}
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) {
if (entry.Value is Stream)
Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), (Stream)entry.Value));
else if (entry.Value is byte[])
Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), new MemoryStream((byte[])entry.Value)));
}
}
}
示例5: makeSureLoadAssemblyResourceMetaData
//确保程序集的资源元数据信息都已加载
private static void makeSureLoadAssemblyResourceMetaData(Assembly assembly)
{
String assemblyName = assembly.GetName().Name;
lock (typeof(ResourceUtils))
{
//嵌入的资源
if (!assemblyEmbedResourceDict.ContainsKey(assembly))
{
assemblyEmbedResourceDict[assembly] = assembly.GetManifestResourceNames();
}
//Resource的资源
string resBaseName = assemblyName + ".g.resources";
if (!assemblyResourceResourceDict.ContainsKey(assembly))
{
assemblyResourceResourceDict[assembly] = new Dictionary<string, string>();
if (assemblyEmbedResourceDict[assembly].Contains(resBaseName))
{
String[] resourceList = new String[0];
using (var stream = assembly.GetManifestResourceStream(resBaseName))
{
if (stream != null)
{
using (var reader = new System.Resources.ResourceReader(stream))
{
resourceList = reader.Cast<DictionaryEntry>().Select(entry =>
(string)entry.Key).ToArray();
}
}
}
foreach (var resource in resourceList)
{
assemblyResourceResourceDict[assembly][resource.Replace('/', '.')] = resource;
}
}
}
}
}
示例6: 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;
}
示例7: LoadChildren
protected override void LoadChildren()
{
EmbeddedResource er = this.Resource as EmbeddedResource;
if (er != null) {
Stream s = er.GetResourceStream();
s.Position = 0;
ResourceReader reader;
try {
reader = new ResourceReader(s);
}
catch {
// NotSupportedException, IOException, BadImageFormatException, ArgumentException
// and any other possible exception
return;
}
try {
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) {
ProcessResourceEntry(entry);
}
}
catch {
}
}
}
示例8: AddTextFilesFromResources
/// <summary>
/// Add text files from assembly resources under specified scope.
/// </summary>
/// <param name="assembly"></param>
/// <param name="scope"></param>
public void AddTextFilesFromResources(Assembly assembly, string scope)
{
Contract.Assert(assembly != null, "assembly is required to have a value.");
Contract.Assert(scope != null, "scope is required to have a value.");
scope = scope.ToLower();
string resourceName = string.Format("{0}.g.resources", assembly.GetName().Name);
Stream resourceStream = assembly.GetManifestResourceStream(resourceName);
if (resourceStream == null)
{
throw new FileNotFoundException(string.Format("Resource file {0} is not found from assembly {1}",
resourceName, assembly.GetName().Name));
}
using (ResourceReader rr = new ResourceReader(resourceStream))
{
var filesToDeploy = rr.Cast<DictionaryEntry>().Where(entry =>
{
string key = entry.Key as string;
if (string.IsNullOrEmpty(key))
{
return false;
}
return key.StartsWith(scope) && (entry.Value is Stream);
}).Select(entry =>
{
string key = entry.Key as string;
key = key.Substring(scope.Length);
if (key.StartsWith("/"))
{
key = key.Substring(1);
}
return Tuple.Create<string, Stream>(key, entry.Value as Stream);
});
if (filesToDeploy.Count() == 0)
{
throw new FileNotFoundException(string.Format("No file is found under path {0}", scope));
}
foreach (var fileEntry in filesToDeploy)
{
using (StreamReader sr = new StreamReader(fileEntry.Item2))
{
if (this.TextFiles.ContainsKey(fileEntry.Item1))
{
this.TextFiles[fileEntry.Item1] = sr.ReadToEnd();
}
else
{
this.TextFiles.Add(fileEntry.Item1, sr.ReadToEnd());
}
}
}
}
}
示例9: LoadChildren
protected override void LoadChildren()
{
EmbeddedResource er = r as EmbeddedResource;
if (er != null) {
try {
Stream s = er.GetResourceStream();
s.Position = 0;
if (er.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)) {
ResourceReader reader = new ResourceReader(s);
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) {
if (entry.Value is Stream)
Children.Add(new ResourceEntryNode(entry.Key.ToString(), (Stream)entry.Value));
}
}
} catch (ArgumentException) {
}
}
}