GetString() public static method

지정된 Class Key에 해당하는 Provider를 제공한다. classKey의 형식은 [AssemblyName|]ResourceName 또는 [FileName|]SectionName 으로 표현된다.
public static GetString ( string classKey, string resourceKey, CultureInfo culture = null ) : string
classKey string
resourceKey string
culture System.Globalization.CultureInfo
return string
Exemplo n.º 1
0
        public void FileResourceTest()
        {
            _factory.GlobalResourceProviderName = "FileResourceProvider";

            string classKey = "Glossary"; // "DEFAULT|Glossary" 와 같다.

            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage"));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("ko")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("ko-KR")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("en")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("en-US")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("en-CA")));

            Assert.IsNotNull(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("en-CA")));

            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome"));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("ko")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("ko-KR")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("en")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("en-US")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("en-CA")));

            Assert.IsNotNull(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("en-CA")));

            classKey = "CommonTerms";

            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello"));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("ko")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("ko-KR")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("en")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("en-US")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("en-CA")));

            Assert.IsNotEmpty(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("en-CA")));
        }
Exemplo n.º 2
0
        public void ExternalResourceTest()
        {
            _factory.GlobalResourceProviderName = "ExternalResourceProvider";

            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "HomePage"));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "HomePage", new CultureInfo("ko")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "HomePage", new CultureInfo("ko-KR")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "HomePage", new CultureInfo("en")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "HomePage", new CultureInfo("en-US")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "HomePage", new CultureInfo("en-CA")));

            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "Welcome"));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "Welcome", new CultureInfo("ko")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "Welcome", new CultureInfo("ko-KR")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "Welcome", new CultureInfo("en")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "Welcome", new CultureInfo("en-US")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|Glossary", "Welcome", new CultureInfo("en-CA")));

            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello"));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("ko")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("ko-KR")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("en")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("en-US")));
            Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("en-CA")));
        }
Exemplo n.º 3
0
 public void ExternalResourceTest2()
 {
     Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello"));
     Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("ko")));
     Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("ko-KR")));
     Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("en")));
     Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("en-US")));
     Console.WriteLine(ResourceProvider.GetString("Sample.ExtResources|CommonTerms", "Hello", new CultureInfo("en-CA")));
 }
        private string GetParameterValue(string paramKey, CultureInfo culture)
        {
            if (IsDebugEnabled)
            {
                log.Debug("Get Parameter value. paramKey=[{0}], culuture=[{1}]", paramKey, culture);
            }

            if (paramKey.IsWhiteSpace())
            {
                return(null);
            }

            string result;

            string resourceFile, resourceKey;

            StringResourceTool.ParseClassKey(paramKey, out resourceFile, out resourceKey);

            // External Resource Provider의 예로 들면
            // 다른 resource file에 있을 시 (resource assembly에는 여러개의 resource file이 존재하고,
            // 다른 resource file의 키값을 조회하기 위해 ${filename|resourceKey} 형태를 취할 수 있다.
            //
            // Resource : ${resourceFile|resourceKey}
            if (resourceFile != StringResourceTool.DEFAULT_ASSEMBLY_NAME)
            {
                result = ResourceProvider.GetString(AssemblyName + StringResourceTool.CLASS_KEY_DELIMITER + resourceFile,
                                                    resourceKey,
                                                    culture);
            }
            else
            {
                result = base.GetObject(paramKey, culture) as string;
            }

            if (IsDebugEnabled)
            {
                log.Debug("Parameter에 해당하는 값을 조회했습니다. paramKey=[{0}], culture=[{1}], paramValue=[{2}]", paramKey, culture, result);
            }

            return(result);
        }
Exemplo n.º 5
0
        public void NHResourceTest()
        {
            if (UnitOfWork.IsStarted == false)
            {
                UnitOfWork.Start();
            }

            _factory.GlobalResourceProviderName = "NHResourceProvider";

            string classKey = @"OtherResources|Glossary";

            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage"));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("ko")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("ko-KR")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("en")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("en-US")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("en-CA")));

            Assert.IsNotNull(ResourceProvider.GetString(classKey, "HomePage", new CultureInfo("en-CA")));

            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome"));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("ko")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("ko-KR")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("en")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("en-US")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("en-CA")));

            Assert.IsNotNull(ResourceProvider.GetString(classKey, "Welcome", new CultureInfo("en-CA")));

            classKey = @"OtherResources|CommonTerms";

            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello"));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("ko")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("ko-KR")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("en")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("en-US")));
            Console.WriteLine(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("en-CA")));

            Assert.IsNotNull(ResourceProvider.GetString(classKey, "Hello", new CultureInfo("en-CA")));
        }