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


C# ResourceManager.GetResourceSet方法代码示例

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


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

示例1: IncludeResources

        public static IHtmlString IncludeResources(this HtmlHelper html)
        {
            var currentCulture = Thread.CurrentThread.CurrentUICulture;

            var sw = new StringWriter();
            sw.WriteLine("<script>");
            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            foreach (string resourceName in executingAssembly.GetManifestResourceNames())
            {
                var resourceKey = resourceName.Replace(".resources", "");

                var resourceManager = new ResourceManager(resourceKey, executingAssembly);

                var shortenedResourceName = resourceKey.Replace("OnBoard.Views.Module.", "");

                var set = resourceManager.GetResourceSet(currentCulture, true, true);
                IDictionaryEnumerator id = set.GetEnumerator();
                while (id.MoveNext())
                {
                    sw.WriteLine("resources.setResource('{0}.{1}','{2}');", shortenedResourceName, id.Key, id.Value.ToString().Replace("'", "\\'"));
                }
            }
            sw.WriteLine("</script>");
            return new HtmlString(sw.ToString());
        }
开发者ID:kevinrjones,项目名称:DevWeek2013,代码行数:26,代码来源:IncludeResources.cs

示例2: Resources_HasAllTranslations

        public void Resources_HasAllTranslations()
        {
            IEnumerable<Language> languages = GlobalizationProviderFactory.CreateProvider().Languages;
            IEnumerable<Type> resourceTypes = Assembly
                .Load("MvcTemplate.Resources")
                .GetTypes()
                .Where(type => type.Namespace.StartsWith("MvcTemplate.Resources."));

            foreach (Type type in resourceTypes)
            {
                ResourceManager manager = new ResourceManager(type);
                IEnumerable<String> resourceKeys = new String[0];

                foreach (Language language in languages)
                {
                    ResourceSet set = manager.GetResourceSet(language.Culture, true, true);
                    resourceKeys = resourceKeys.Union(set.Cast<DictionaryEntry>().Select(resource => resource.Key.ToString()));
                    resourceKeys = resourceKeys.Distinct();
                }

                foreach (Language language in languages)
                {
                    ResourceSet set = manager.GetResourceSet(language.Culture, true, true);
                    foreach (String key in resourceKeys)
                        Assert.True(!String.IsNullOrEmpty(set.GetString(key)),
                            String.Format("{0}, does not have translation for '{1}' in {2} language.",
                                type.FullName, key, language.Culture.EnglishName));
                }
            }
        }
开发者ID:vothlizard,项目名称:MVC.Template,代码行数:30,代码来源:ResourcesTests.cs

示例3: GetResourcesJavaScript

        public ActionResult GetResourcesJavaScript(string resxFileName)
        {
            ResourceManager resourceManager = null;
            switch (resxFileName.ToLower())
            {
                case "globalsresource":
                    {
                        resourceManager = new ResourceManager("ControleFinanceiro.CORE.Resources.GlobalsResource", typeof(GlobalsResource).Assembly);
                        break;
                    }
                case "labelsresource":
                    {
                        resourceManager = new ResourceManager("ControleFinanceiro.CORE.Resources.LabelsResource", typeof(LabelsResource).Assembly);
                        break;
                    }
                case "messagesresource":
                    {
                        resourceManager = new ResourceManager("ControleFinanceiro.CORE.Resources.MessagesResource", typeof(MessagesResource).Assembly);
                        break;
                    }
            }

            if(resourceManager != null)
            {
                var resourceSet = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

                var resourceDictionary = resourceSet.Cast<DictionaryEntry>()
                                    .ToDictionary(entry => entry.Key.ToString(), entry => entry.Value.ToString());

                var json = Serializer.Serialize(resourceDictionary);
                var javaScript = string.Format("window.Resources = window.Resources || {{}}; window.Resources.{0} = {1};", resxFileName, json);
                return JavaScript(javaScript);
            }
            return JavaScript("");
        }
开发者ID:fmanoellima,项目名称:ControleFinanceiro,代码行数:35,代码来源:ResourcesController.cs

示例4: CreateResourceStringGetter

        public static Func<string, string> CreateResourceStringGetter(
            [NotNull] Assembly assembly,
            string baseName,
            CultureInfo culture)
        {
            if (assembly == null)
                throw new ArgumentNullException("assembly");

            if (baseName != null)
            {
                var rm = new ResourceManager(baseName, assembly);
                var resSets = new List<ResourceSet>();
                var curCulture = culture ?? CultureInfo.CurrentUICulture;
                do
                {
                    resSets.Add(rm.GetResourceSet(curCulture, true, true));
                    if (curCulture.Parent == null || curCulture == curCulture.Parent)
                        break;
                    curCulture = curCulture.Parent;
                } while (true);

                return
                    name =>
                        resSets
                            .Select(rs => rs.GetString(name ?? ""))
                            .FirstOrDefault(s => s != null);
            }
            return
                name =>
                {
                    throw new ApplicationException(
                        "Запрошена ресурсная строка '{0}', но не указан ресурсный файл.".FormatStr(name));
                };
        }
开发者ID:permyakov,项目名称:janus,代码行数:34,代码来源:ResourceHelper.cs

示例5: LocalizationExtenderProvider

 public LocalizationExtenderProvider(ISite serviceProvider, IComponent baseComponent)
 {
     this.serviceProvider = serviceProvider;
     this.baseComponent = baseComponent;
     if (serviceProvider != null)
     {
         IExtenderProviderService service = (IExtenderProviderService) serviceProvider.GetService(typeof(IExtenderProviderService));
         if (service != null)
         {
             service.AddExtenderProvider(this);
         }
     }
     this.language = CultureInfo.InvariantCulture;
     ResourceManager manager = new ResourceManager(baseComponent.GetType());
     if (manager != null)
     {
         ResourceSet set = manager.GetResourceSet(this.language, true, false);
         if (set != null)
         {
             object obj2 = set.GetObject("$this.Localizable");
             if (obj2 is bool)
             {
                 this.defaultLocalizable = (bool) obj2;
                 this.localizable = this.defaultLocalizable;
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:LocalizationExtenderProvider.cs

示例6: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Extracts resources from .net .resources files or assemblies containing *.g.resources files, dumps them in the working directory.");

            if (args.Count() != 1) {
                Console.WriteLine("Usage:  first argument should be a .resource file or an assembly.");
                return;
            }

            ResourceManager manager = null;

            //try{
                try{
                    Assembly assembly = Assembly.LoadFile(args[0]);

                    manager = new ResourceManager(assembly.GetName().Name + ".g", assembly);
                }catch(BadImageFormatException e){
                    // Ok, not an assembly.
                }

                if (manager == null){
                    manager = ResourceManager.CreateFileBasedResourceManager(Path.GetFileNameWithoutExtension(args[0]), Path.GetDirectoryName(args[0]), null);
                }

                //GetResourceSet() will return null unless I do a bogus fetch of a resource.  I probably need to RTFM more.
                try{
                    Object hello = manager.GetObject("buttwars");
                } catch (Exception) { }

                ResourceSet resourceset = manager.GetResourceSet(CultureInfo.InvariantCulture, false, false);

                foreach (DictionaryEntry resource in resourceset){
                    Console.WriteLine(resource.Key);

                    if (resource.Value is UnmanagedMemoryStream) {
                        UnmanagedMemoryStream stream = (UnmanagedMemoryStream)resource.Value;
                        String path = (String)resource.Key;
                        String directory = Path.GetDirectoryName(path);

                        if(path == null) {
                            Console.WriteLine("null?");
                        }

                        if (directory != null && directory.Length != 0) {
                            Directory.CreateDirectory(directory);
                        }

                        FileStream outputstream = File.Create(path);

                        stream.CopyTo(outputstream);

                        outputstream.Close();
                    }
                }

                Console.WriteLine(manager.ToString());
            /*}catch(Exception e){
                Console.Error.WriteLine(e.ToString());
            }*/
        }
开发者ID:philippelatulippe,项目名称:DotNetResourceExtractor,代码行数:60,代码来源:Program.cs

示例7: GetImplementedCultures

        public static IEnumerable<CultureInfo> GetImplementedCultures(ResourceManager rm)
        {
            var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures)
                .Where(i => rm.GetResourceSet(i, true, false) != null);

            return cultures;
        }
开发者ID:ripa-alexandr,项目名称:weather,代码行数:7,代码来源:CultureHelpers.cs

示例8: LoadResources

        public static void LoadResources(string strCulture)
        {
            try
            {
                System.Reflection.Assembly targetAsmbly = System.Reflection.Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "PACT.Globalization.dll");
                System.Reflection.Assembly satAsmbly = targetAsmbly.GetSatelliteAssembly(new CultureInfo(strCulture));
                string[] resources = satAsmbly.GetManifestResourceNames();
                string strName = "";
                string strValue = "";
                UIResources.Clear();
                foreach (string resource in resources)
                {
                    string baseName = resource.Substring(0, resource.LastIndexOf('.'));
                    ResourceManager resourceManager = new ResourceManager(baseName, satAsmbly);
                    ResourceSet resourceSet = resourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
                    IDictionaryEnumerator enumerator = resourceSet.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        strName = enumerator.Key.ToString();
                        strValue = enumerator.Value.ToString();
                        UIResources.Add(strName, strValue);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
开发者ID:merlin2504,项目名称:RD12,代码行数:30,代码来源:ViewResourceManager.cs

示例9: GetAllLanguages

        public IEnumerable<Language> GetAllLanguages()
        {
            if(!mCachedLanguageList.Any())
            {
                // Based on http://stackoverflow.com/a/11047894/2579010
                var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
                var resourceManager = new ResourceManager(typeof(Auctioneer.Resources.Shared.Layout));

                foreach(var culture in allCultures)
                {
                    var resourcesForThisCulture = resourceManager.GetResourceSet(culture, createIfNotExists: true, tryParents: false);
                    if(resourcesForThisCulture != null)
                    {
                        var language = new Language
                        {
                            LangCode    = !culture.Equals(CultureInfo.InvariantCulture) ? culture.TwoLetterISOLanguageName : "en",
                            DisplayName = !culture.Equals(CultureInfo.InvariantCulture) ? culture.DisplayName              : "English"
                        };

                        mCachedLanguageList.Add(language);
                    }
                }
            }

            return mCachedLanguageList;
        }
开发者ID:Strachu,项目名称:Auctioneer,代码行数:26,代码来源:LanguageService.cs

示例10: SwatchesProvider

        public SwatchesProvider()
        {
            var assembly = Assembly.GetExecutingAssembly();
            var resourcesName = assembly.GetName().Name + ".g";
            var manager = new ResourceManager(resourcesName, assembly);
            var resourceSet = manager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
            var dictionaryEntries = resourceSet.OfType<DictionaryEntry>().ToList();
            var assemblyName = assembly.GetName().Name;

            var regex = new Regex(@"^themes\/materialdesigncolor\.(?<name>[a-z]+)\.(?<type>primary|accent)\.baml$");

            Swatches =
                dictionaryEntries
                .Select(x => new { key = x.Key.ToString(), match = regex.Match(x.Key.ToString()) })
                .Where(x => x.match.Success && x.match.Groups["name"].Value != "black")
                .GroupBy(x => x.match.Groups["name"].Value)
                .Select(x =>
                CreateSwatch
                (
                    x.Key,
                    Read(assemblyName, x.SingleOrDefault(y => y.match.Groups["type"].Value == "primary")?.key),
                    Read(assemblyName, x.SingleOrDefault(y => y.match.Groups["type"].Value == "accent")?.key)
                ))
                .ToList();

        }
开发者ID:ItsJustSean,项目名称:MaterialDesignInXamlToolkit,代码行数:26,代码来源:SwatchesProvider.cs

示例11: load_images

        public void load_images()
        {
            List<string> resource_paths = new List<string>();
            var assembly = Assembly.GetExecutingAssembly();
            var buffer = new ResourceManager(assembly.GetName().Name + ".g", assembly);
            try
            {
                var list = buffer.GetResourceSet(CultureInfo.CurrentCulture, true, true);
                foreach (DictionaryEntry item in list)
                {
                    resource_paths.Add((string)item.Key);
                }
            }
            finally
            {
                buffer.ReleaseAllResources();
            }

            all_images = new List<photo>();
            foreach (string current_path in resource_paths)
            {
                if (current_path.Contains(".jpg"))
                {
                    BitmapImage another_image = new BitmapImage(new Uri(@"/" + current_path, UriKind.Relative));
                    all_images.Add(new photo(another_image));
                }
            }

            faces_combo_box.ItemsSource = all_images;
            faces_combo_box.SelectedItem = faces_combo_box.Items[0];
        }
开发者ID:Saroko-dnd,项目名称:My_DZ,代码行数:31,代码来源:change_image_window.xaml.cs

示例12: Resources_HasEquivalents

        public void Resources_HasEquivalents()
        {
            IEnumerable<CultureInfo> languages = new[] { new CultureInfo("en-GB"), new CultureInfo("lt-LT") };
            IEnumerable<Type> resourceTypes = Assembly
                .Load("MvcTemplate.Resources")
                .GetTypes()
                .Where(type => type.Namespace.StartsWith("MvcTemplate.Resources."));

            foreach (Type type in resourceTypes)
            {
                ResourceManager manager = new ResourceManager(type);
                IEnumerable<String> resourceKeys = new String[0];

                foreach (ResourceSet set in languages.Select(language => manager.GetResourceSet(language, true, true)))
                {
                    resourceKeys = resourceKeys.Union(set.Cast<DictionaryEntry>().Select(resource => resource.Key.ToString()));
                    resourceKeys = resourceKeys.Distinct();
                }

                foreach (CultureInfo language in languages)
                {
                    ResourceSet set = manager.GetResourceSet(language, true, true);
                    foreach (String key in resourceKeys)
                        Assert.True((set.GetObject(key) ?? "").ToString() != "",
                            String.Format("{0}, does not have translation for '{1}' in {2} language.",
                                type.FullName, key, language.EnglishName));
                }
            }
        }
开发者ID:zarinbal,项目名称:MVC5.Template,代码行数:29,代码来源:ResourcesTests.cs

示例13: SetCustomResource

        ///<summary>
        /// In case you want to use Saber's implemented language file, but use ith with your own resource file, you can use this property to set it.
        /// In case you've set the Language property to a custom built class, setting this property will reset it to the default Saber class.
        ///</summary>
        public static void SetCustomResource(ResourceManager resourceManager)
        {
            if (resourceManager == null)
                return;

            var newKeys = new Collection<string>();

            var newResourceSet = resourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true).GetEnumerator();

            while (newResourceSet.MoveNext())
                newKeys.Add(newResourceSet.Key.ToString());

            var resourceType = typeof(SaberRes);
            var properties = resourceType.GetProperties(BindingFlags.Static | (resourceType.IsPublic
                                                                                       ? BindingFlags.Public
                                                                                       : BindingFlags.NonPublic));

            var foundAllKeys = properties.Select(x => x.Name)
                                       .Intersect(newKeys)
                                       .Count() == (properties.Length - 2);

            if (!foundAllKeys)
                return;

            var resourceManagerField = resourceType.GetField("resourceMan", BindingFlags.Static | BindingFlags.NonPublic);

            if (resourceManagerField == null)
                return;

            resourceManagerField.SetValue(null, resourceManager);

            ResetLanguageInstance();
        }
开发者ID:StevenThuriot,项目名称:Saber,代码行数:37,代码来源:Saber.cs

示例14: ResxTranslationProvider

 public ResxTranslationProvider(ResourceManager resourceManager)
 {
     _resourceManager = resourceManager;
     _languages = CultureInfo.GetCultures(CultureTypes.AllCultures)
                             .Where(x => x.TwoLetterISOLanguageName != "iv" &&
                                        _resourceManager.GetResourceSet(x, true, false) != null)
                             .ToList();
 }
开发者ID:JohanLarsson,项目名称:WcfBox,代码行数:8,代码来源:ResxTranslationProvider.cs

示例15: ReadHtmlFiles

        static void ReadHtmlFiles(ResourceManager resourceManager)
        {
            var rs = resourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
            var it = rs.GetEnumerator();

            while (it.MoveNext())
                TestHtml(it.Value.ToString(), it.Key.ToString());
        }
开发者ID:rrsc,项目名称:AngleSharp,代码行数:8,代码来源:Program.cs


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