Beispiel #1
0
        private IList <DictionaryEntry> GetAllAssemblyResources(Assembly assembly)
        {
#if debug
            var resourcesName = assembly.GetName().Name + ".g";
            var manager       = new ResourceManager(resourcesName, assembly);
            var resourceSet   = manager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
            return(resourceSet.OfType <DictionaryEntry>().ToList());
#else
            string resName = assembly.GetName().Name + ".g.resources";
            using (var stream = assembly.GetManifestResourceStream(resName))
            {
                using (var reader = new System.Resources.ResourceReader(stream))
                {
                    return(reader.Cast <DictionaryEntry>().ToList());
                }
            }
#endif
        }
        static void Main(string[] args)
        {
            // Имя ресурсного файла (файлов)
            string [] resNames = Assembly.GetCallingAssembly().GetManifestResourceNames();
            resource = resNames[0];

            // Загружаем
            string          baseName        = resource.Substring(0, resource.LastIndexOf('.'));
            ResourceManager resourceManager = new ResourceManager(baseName, Assembly.GetExecutingAssembly());

            // Hashtable ресурсов
            ResourceSet resourceSet = resourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);

            // Доступ к ресурсам
            //   Строка
            Console.WriteLine(resourceSet.GetString("Str1"));
            //   Тип System.Int32
            Console.WriteLine(resourceSet.GetObject("Int1").GetType());
            Console.WriteLine((Int32)resourceSet.GetObject("Int1"));

            Console.ReadLine();
        }