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


C# ResourceReader.Dispose方法代码示例

本文整理汇总了C#中System.Resources.ResourceReader.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceReader.Dispose方法的具体用法?C# ResourceReader.Dispose怎么用?C# ResourceReader.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Resources.ResourceReader的用法示例。


在下文中一共展示了ResourceReader.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Exception_Enumerator_Value

        public static void Exception_Enumerator_Value()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                using (var ms2 = new MemoryStream())
                {
                    using (var rw = GenerateResourceStream(s_dict, ms2))
                    {
                        ms2.Seek(0L, SeekOrigin.Begin);
                        var rr1 = new ResourceReader(ms2);

                        IDictionaryEnumerator enumarator = rr1.GetEnumerator();
                        rr1.Dispose();
                        var shouldnotgethere = enumarator.Value;


                    }
                }
            });
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:20,代码来源:ResourceReaderUnitTest.cs

示例2: ExceptionVerifier

        public ExceptionVerifier(string assemblyName, ExceptionVerificationFlags flags, ITestOutputHelper output)
        {
            _output = output;

            if (assemblyName == null)
                throw new VerifyException("Assembly name cannot be null");

            _verificationFlags = flags;

            try
            {
                switch (assemblyName.ToUpper())
                {
                    case "SYSTEM.XML":
                        {
                            var dom = new XmlDocument();
                            _asm = dom.GetType().GetTypeInfo().Assembly;
                        }
                        break;
                    //case "SYSTEM.DATA":
                    //{
                    //    var ds = new DataSet();
                    //    asm = ds.GetType().Assembly;
                    //}
                    //    break;
                    default:
                        throw new FileLoadException("Cannot load assembly from " + GetRuntimeInstallDir() + assemblyName + ".dll");
                        //asm = Assembly.LoadFrom(GetRuntimeInstallDir() + assemblyName + ".dll");
                        //break;
                }

                if (_asm == null)
                    throw new VerifyException("Can not load assembly " + assemblyName);

                // let's determine if this is a loc run, if it is then we need to load satellite assembly
                _locAsm = null;
                if (!CultureInfo.CurrentCulture.Equals(new CultureInfo("en-US")) && !CultureInfo.CurrentCulture.Equals(new CultureInfo("en")))
                {
                    try
                    {
                        throw new NotImplementedException("Cannot Load Satellite assembly");
                        // load satellite assembly
                        //locAsm = asm.GetSatelliteAssembly(new CultureInfo(CultureInfo.CurrentCulture.Parent.IetfLanguageTag));
                    }
                    catch (FileNotFoundException e1)
                    {
                        _output.WriteLine(e1.ToString());
                    }
                    catch (FileLoadException e2)
                    {
                        _output.WriteLine(e2.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                _output.WriteLine("Exception: " + e.Message);
                _output.WriteLine("Stack: " + e.StackTrace);
                throw new VerifyException("Error while loading assembly");
            }

            string[] resArray;
            Stream resStream = null;
            var bFound = false;

            // Check that assembly manifest has resources
            if (null != _locAsm)
                resArray = _locAsm.GetManifestResourceNames();
            else
                resArray = _asm.GetManifestResourceNames();

            foreach (var s in resArray)
            {
                if (s.EndsWith(".resources"))
                {
                    resStream = null != _locAsm ? _locAsm.GetManifestResourceStream(s) : _asm.GetManifestResourceStream(s);
                    bFound = true;
                    if (bFound && resStream != null)
                    {
                        // Populate hashtable from resources
                        var resReader = new ResourceReader(resStream);
                        if (_resources == null)
                        {
                            _resources = new Hashtable();
                        }
                        var ide = resReader.GetEnumerator();
                        while (ide.MoveNext())
                        {
                            if (!_resources.ContainsKey(ide.Key.ToString()))
                                _resources.Add(ide.Key.ToString(), ide.Value.ToString());
                        }
                        resReader.Dispose();
                    }
                    //break;
                }
            }

            if (!bFound || resStream == null)
                throw new VerifyException("GetManifestResourceStream() failed");
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:100,代码来源:ExceptionVerifier.cs

示例3: ExceptionforResourceReaderDispose01

        public static void ExceptionforResourceReaderDispose01()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                using (var ms2 = new MemoryStream())
                {
                    using (var rw = GenerateResourceStream(s_dict, ms2))
                    {
                        ms2.Seek(0L, SeekOrigin.Begin);
                        var rr1 = new ResourceReader(ms2);

                        rr1.Dispose();
                        var s_found_list = new List<string>();
                        foreach (DictionaryEntry entry in rr1)
                        {
                            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);
                        }

                    }
                }
            });
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:26,代码来源:ResourceReaderUnitTest.cs

示例4: GetResource

 private string GetResource(string name)
 {
     string result = string.Empty;
     Stream stream = Assembly.GetEntryAssembly().GetManifestResourceStream("Concierge_Manager.Properties.Resources.resources");
     IResourceReader reader = new ResourceReader(stream);
     var query = from DictionaryEntry entry in reader
                 where entry.Key as string == name
                 select entry.Value;
     if (query.Count() == 1)
     {
         result = query.First() as string;
     }
     reader.Dispose();
     stream.Dispose();
     return result;
 }
开发者ID:cpbuck12,项目名称:Db,代码行数:16,代码来源:ObjectForScripting.cs


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