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


C# ResourceReader.Cast方法代码示例

本文整理汇总了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;
        }
开发者ID:JoseCasimiro44,项目名称:RulesUtils,代码行数:26,代码来源:ResourcesMustBeReferencedRule.cs

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

示例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);
        }
开发者ID:Grrremlins-ADV,项目名称:ChessWeb,代码行数:48,代码来源:PieceSetStandard.cs

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

示例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;
                 }
             }
         }
     }
 }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:38,代码来源:ResourceUtils.cs

示例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;
		}
开发者ID:ALyman,项目名称:ILSpy,代码行数:25,代码来源:TestRunner.cs

示例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 {
         }
     }
 }
开发者ID:BahNahNah,项目名称:dnSpy,代码行数:24,代码来源:ResourcesFileTreeNode.cs

示例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());
                        }
                    }
                }
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:62,代码来源:WebAppSetupOptions.cs

示例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) {
         }
     }
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:18,代码来源:ResourceListTreeNode.cs


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