當前位置: 首頁>>代碼示例>>C#>>正文


C# CultureInfo.Clone方法代碼示例

本文整理匯總了C#中System.Globalization.CultureInfo.Clone方法的典型用法代碼示例。如果您正苦於以下問題:C# CultureInfo.Clone方法的具體用法?C# CultureInfo.Clone怎麽用?C# CultureInfo.Clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Globalization.CultureInfo的用法示例。


在下文中一共展示了CultureInfo.Clone方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetDateFormatInternal

 internal static DateTimeFormatInfo GetDateFormatInternal(CultureInfo culture) {
     if (culture is PersianCultureInfo || culture.Calendar is PersianCalendar)
         return culture.DateTimeFormat;
     var foundCal = culture.OptionalCalendars.OfType<PersianCalendar>().FirstOrDefault();
     if (foundCal != null) {
         var dtfi = ((CultureInfo)culture.Clone()).DateTimeFormat;
         if (!dtfi.IsReadOnly)
             dtfi.Calendar = foundCal;
         return dtfi;
     }
     return GetDefaultDateFormat(culture);
 }
開發者ID:kavand,項目名稱:Kavand.Windows.Controls,代碼行數:12,代碼來源:PersianCalendarEngine.cs

示例2: TestClone2

 public void TestClone2()
 {
     CultureInfo myCultureInfo = new CultureInfo("en");
     CultureInfo myClone = myCultureInfo.Clone() as CultureInfo;
     Assert.True(myClone.Equals(myCultureInfo));
     Assert.NotSame(myClone, myCultureInfo);
 }
開發者ID:noahfalk,項目名稱:corefx,代碼行數:7,代碼來源:CultureInfoClone.cs

示例3: PosTest2

        public void PosTest2()
        {
            DateTimeFormatInfo expected = new CultureInfo("en-us").DateTimeFormat;
            VerificationHelper(expected, expected.Clone());

            expected = new CultureInfo("fr-FR").DateTimeFormat;
            VerificationHelper(expected, expected.Clone());
        }
開發者ID:er0dr1guez,項目名稱:corefx,代碼行數:8,代碼來源:DateTimeFormatInfoClone.cs

示例4: CodeDomLocalizationProvider

 public CodeDomLocalizationProvider(IServiceProvider provider, CodeDomLocalizationModel model, CultureInfo[] supportedCultures)
 {
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     if (supportedCultures == null)
     {
         throw new ArgumentNullException("supportedCultures");
     }
     this._model = model;
     this._supportedCultures = (CultureInfo[]) supportedCultures.Clone();
     this.Initialize(provider);
 }
開發者ID:Reegenerator,項目名稱:Sample-CustomizeDatasetCS,代碼行數:14,代碼來源:CodeDomLocalizationProvider.cs

示例5: TestCachingWithClonedCulture

        public void TestCachingWithClonedCulture()
        {
            var original = new CultureInfo("en-US");
            var clone = (CultureInfo) original.Clone();
            Assert.AreEqual(original.Name, clone.Name);
            clone.DateTimeFormat.DateSeparator = "@@@";

            // Fool Noda Time into believing both are read-only, so it can use a cache...
            original = CultureInfo.ReadOnly(original);
            clone = CultureInfo.ReadOnly(clone);

            var nodaOriginal = NodaFormatInfo.GetFormatInfo(original);
            var nodaClone = NodaFormatInfo.GetFormatInfo(clone);
            Assert.AreEqual(original.DateTimeFormat.DateSeparator, nodaOriginal.DateSeparator);
            Assert.AreEqual(clone.DateTimeFormat.DateSeparator, nodaClone.DateSeparator);
        }
開發者ID:nicklbailey,項目名稱:nodatime,代碼行數:16,代碼來源:NodaFormatInfoTest.cs

示例6: TestCachingWithClonedCulture

        public void TestCachingWithClonedCulture()
        {
            var original = new CultureInfo("en-US");
            var clone = (CultureInfo) original.Clone();
            Assert.AreEqual(original.Name, clone.Name);
            var dayNames = clone.DateTimeFormat.DayNames;
            dayNames[1] = "@@@";
            clone.DateTimeFormat.DayNames = dayNames;

            // Fool Noda Time into believing both are read-only, so it can use a cache...
            original = CultureInfo.ReadOnly(original);
            clone = CultureInfo.ReadOnly(clone);

            var nodaOriginal = NodaFormatInfo.GetFormatInfo(original);
            var nodaClone = NodaFormatInfo.GetFormatInfo(clone);
            Assert.AreEqual(original.DateTimeFormat.DayNames[1], nodaOriginal.LongDayNames[1]);
            Assert.AreEqual(clone.DateTimeFormat.DayNames[1], nodaClone.LongDayNames[1]);
            // Just check we made a difference...
            Assert.AreNotEqual(nodaOriginal.LongDayNames[1], nodaClone.LongDayNames[1]);
        }
開發者ID:ivandrofly,項目名稱:nodatime,代碼行數:20,代碼來源:NodaFormatInfoTest.cs

示例7: ReadOnly

		public static CultureInfo ReadOnly(CultureInfo ci)
		{
			if(ci==null) {
				throw new ArgumentNullException("ci");
			}

			if(ci.m_isReadOnly) {
				return(ci);
			} else {
				CultureInfo new_ci=(CultureInfo)ci.Clone ();
				new_ci.m_isReadOnly=true;
				if (new_ci.numInfo != null)
					new_ci.numInfo = NumberFormatInfo.ReadOnly (new_ci.numInfo);
				if (new_ci.dateTimeInfo != null)
					new_ci.dateTimeInfo = DateTimeFormatInfo.ReadOnly (new_ci.dateTimeInfo);
				if (new_ci.textInfo != null)
					new_ci.textInfo = TextInfo.ReadOnly (new_ci.textInfo);
				return(new_ci);
			}
		}
開發者ID:shana,項目名稱:mono,代碼行數:20,代碼來源:CultureInfo.cs

示例8: CloneNeutral

		[Test] // bug #77347
		public void CloneNeutral ()
		{
			CultureInfo culture = new CultureInfo ("en");
			CultureInfo cultureClone = culture.Clone () as CultureInfo;
			Assert.IsTrue (culture.Equals (cultureClone));
		}
開發者ID:sesef,項目名稱:mono,代碼行數:7,代碼來源:CultureInfoTest.cs

示例9: TestClone

 public void TestClone()
 {
     CultureInfo myCultureInfo = new CultureInfo("fr-FR");
     CultureInfo myClone = myCultureInfo.Clone() as CultureInfo;
     Assert.True(myClone.Equals(myCultureInfo));
 }
開發者ID:noahfalk,項目名稱:corefx,代碼行數:6,代碼來源:CultureInfoEquals.cs

示例10: GetDateFormat

        /// <summary>
        /// Ripped straight from .Net FX.
        /// </summary>
        /// <param name="culture"></param>
        /// <returns></returns>
        internal static DateTimeFormatInfo GetDateFormat(CultureInfo culture)
        {
            if (culture.Calendar is GregorianCalendar)
            {
                return culture.DateTimeFormat;
            }
            else
            {
                GregorianCalendar foundCal = null;
                DateTimeFormatInfo dtfi = null;

                foreach (System.Globalization.Calendar cal in culture.OptionalCalendars)
                {
                    if (cal is GregorianCalendar)
                    {
                        // Return the first Gregorian calendar with CalendarType == Localized
                        // Otherwise return the first Gregorian calendar
                        if (foundCal == null)
                        {
                            foundCal = cal as GregorianCalendar;
                        }

                        if (((GregorianCalendar)cal).CalendarType == GregorianCalendarTypes.Localized)
                        {
                            foundCal = cal as GregorianCalendar;
                            break;
                        }
                    }
                }

                if (foundCal == null)
                {
                    // if there are no GregorianCalendars in the OptionalCalendars list, use the invariant dtfi
                    dtfi = ((CultureInfo)CultureInfo.InvariantCulture.Clone()).DateTimeFormat;
                    dtfi.Calendar = new GregorianCalendar();
                }
                else
                {
                    dtfi = ((CultureInfo)culture.Clone()).DateTimeFormat;
                    dtfi.Calendar = foundCal;
                }

                return dtfi;
            }
        }
開發者ID:terriblememory,項目名稱:MaterialDesignInXamlToolkit,代碼行數:50,代碼來源:MaterialDateDisplay.cs

示例11: Clone

	public void Clone ()
	{
		TextInfo enus = new CultureInfo ("en-US").TextInfo;
		TextInfo clone = (TextInfo) enus.Clone ();
		CompareProperties (enus, clone, true);
	}
開發者ID:sushihangover,項目名稱:playscript,代碼行數:6,代碼來源:TextInfoTest.cs

示例12: ReadOnly

		public static CultureInfo ReadOnly(CultureInfo ci)
		{
			if(ci==null) {
				throw new ArgumentNullException("ci");
			}

			if(ci.m_isReadOnly) {
				return(ci);
			} else {
				CultureInfo new_ci=(CultureInfo)ci.Clone ();
				new_ci.m_isReadOnly=true;
				if (new_ci.numInfo != null)
					new_ci.numInfo = NumberFormatInfo.ReadOnly (new_ci.numInfo);
				if (new_ci.dateTimeInfo != null)
					new_ci.dateTimeInfo = DateTimeFormatInfo.ReadOnly (new_ci.dateTimeInfo);
#if NET_2_0
				// TextInfo doesn't have a ReadOnly method in 1.1...
				if (new_ci.textInfo != null)
					new_ci.textInfo = TextInfo.ReadOnly (new_ci.textInfo);
#endif
				return(new_ci);
			}
		}
開發者ID:runefs,項目名稱:Marvin,代碼行數:23,代碼來源:CultureInfo.cs

示例13: CreateTraditionalCulture

        // Create a modifiable culture with the same properties as the specified number culture,
        // but with digits '0' through '9' starting at the specified unicode value.
        private CultureInfo CreateTraditionalCulture(CultureInfo numberCulture, int firstDigit, bool arabic)
        {
            // Create the digit culture by cloning the given number culture. According to MSDN, 
            // "CultureInfo.Clone is a shallow copy with exceptions. The objects returned by 
            // the NumberFormat and the DateTimeFormat properties are also cloned, so that the 
            // CultureInfo clone can modify the properties of NumberFormat and DateTimeFormat 
            // without affecting the original CultureInfo."
            CultureInfo digitCulture = (CultureInfo)numberCulture.Clone();

            // Create the array of digits.
            string[] digits = new string[10];

            if (firstDigit < 0x10000)
            {
                for (int i = 0; i < 10; ++i)
                {
                    digits[i] = new string((char)(firstDigit + i), 1);
                }
            }
            else
            {
                for (int i = 0; i < 10; ++i)
                {
                    int n = firstDigit + i - 0x10000;

                    digits[i] = new string(
                        new char[] {
                            (char)((n >> 10) | 0xD800),     // high surrogate
                            (char)((n & 0x03FF) | 0xDC00)   // low surrogate
                            }
                        );
                }
            }

            // Set the digits.
            digitCulture.NumberFormat.NativeDigits = digits;

            if (arabic)
            {
                digitCulture.NumberFormat.PercentSymbol = "\u066a";
                digitCulture.NumberFormat.NumberDecimalSeparator = "\u066b";
                digitCulture.NumberFormat.NumberGroupSeparator = "\u066c";
            }
            else
            {
                digitCulture.NumberFormat.PercentSymbol = "%";
                digitCulture.NumberFormat.NumberDecimalSeparator = ".";
                digitCulture.NumberFormat.NumberGroupSeparator = ",";
            }

            return digitCulture;
        }
開發者ID:JianwenSun,項目名稱:cc,代碼行數:54,代碼來源:NumberSubstitution.cs

示例14: displayBankData

        // Display accounts, transactions, and statements for customer
        //   with input first name & last name
        //  (there may be more than one customer with the same first name and last name)
        // Return true if customer was found in DB, otherwise return false
        public static bool displayBankData(string custFirstName, string custLastName)
        {
            const string LINESEPARATOR = "--------------------------------------------------------";
            const string CURRENTCULTURE = "en-us"; // for formatting negative currency values

            using (var db = new LargeBankEntities())
            {
                // Get customer data (return if customer was not found)
                var customerList = db.Customers.Where(c => c.FirstName == custFirstName &&
                                                    c.LastName == custLastName);

                if (customerList.Count() == 0)
                {
                    return false;
                }

                // Print data for each customer that was found in the DB
                foreach (var customer in customerList)
                {
                    // Print the customer data
                    Console.WriteLine(LINESEPARATOR);
                    Console.WriteLine("Customer: {0} {1} joined LargeBank on: {2}",
                        customer.FirstName, customer.LastName, customer.CreatedDate.ToShortDateString());
                    Console.WriteLine("Address: \n" + customer.Address1);
                    if (customer.Address2 != null)
                    {
                        Console.WriteLine(customer.Address2);
                    }
                    Console.Write(customer.City + ", " + customer.State);
                    if (customer.Zip == null)
                    {
                        Console.WriteLine("");
                    }
                    else
                    {
                        Console.WriteLine(" " + customer.Zip);
                    }

                    // Set number format info to use negative sign instead of parentheses
                    //  for negative numbers in the transaction data
                    var originalCultureInfo = new CultureInfo(CURRENTCULTURE);
                    var modifiedCultureInfo = (CultureInfo)originalCultureInfo.Clone();
                    modifiedCultureInfo.NumberFormat.CurrencyNegativePattern = 1;

                    // Print data for each account belonging to the customer
                    foreach (var account in customer.Accounts)
                    {
                        Console.WriteLine(LINESEPARATOR);
                        Console.WriteLine("--Balance for account# " + account.AccountNumber +
                                " is: " + account.Balance.ToString("C"));

                        // Print the transaction data for the account
                        foreach (var transaction in account.Transactions)
                        {
                            Console.WriteLine("---Transaction date: {0}, amount: {1}",
                                   transaction.TransactionDate.ToShortDateString(),
                                   string.Format(modifiedCultureInfo, "{0:C}", transaction.Amount));
                        }

                        // Print the statement data for the account
                        foreach (var statement in account.Statements)
                        {
                            Console.WriteLine("---Statement start date: {0}, end date: {1}",
                                   statement.StartDate.ToShortDateString(),
                                    statement.EndDate.ToShortDateString());
                            if (statement.CreatedDate != null)
                            {
                                Console.WriteLine("----Created on: ",
                                    statement.CreatedDate.Value.ToShortDateString());
                            }
                        }
                    }
                    Console.WriteLine(LINESEPARATOR + "\n");
                }
            }
            return true;
        }
開發者ID:kds-snyder,項目名稱:16-LargeBank-ORM,代碼行數:81,代碼來源:LargeBankService.cs

示例15: GetCultureInfo

		public CultureInfo GetCultureInfo(string name) {
			if(name == null) {
				throw new ArgumentNullException("name");
			}
			CultureInfo cultureInfo = null;
			if(cultureInfoCache.ContainsKey(name)) {
				cultureInfo = cultureInfoCache[name];
			}
			if(cultureInfo != null)
				return (CultureInfo)cultureInfo.Clone();

			cultureInfo = new CultureInfo(name);

			var config = ConfigRepository.Instance.GetConfig(ConfigRepository.Instance.SystemConfigKey, true);
			if(config == null) {
				return cultureInfo;
			}

			string dateTimeFormatConfigKey = string.Format("cultureConfig/culture[@value=\"{0}\"]/dateTimeFormat", name);
			if(config.ContainsKey(dateTimeFormatConfigKey)) {
				IConfig dateTimeFormatConfig = config.GetConfigSection(dateTimeFormatConfigKey);

				string[] abbreviatedMonthGenitiveNames = dateTimeFormatConfig.GetValueArray("abbreviatedMonthGenitiveNames", "abbreviatedMonthGenitiveName");
				if(abbreviatedMonthGenitiveNames.Length > 0) {
					try {
						cultureInfo.DateTimeFormat.AbbreviatedMonthGenitiveNames = abbreviatedMonthGenitiveNames;
					} catch(ArgumentException ex) {
						throw new ConfigurationException(string.Format("[{0}/abbreviatedMonthGenitiveNames] {1}", dateTimeFormatConfigKey, ex.Message));
					}
				}

				string[] monthGenitiveNames = dateTimeFormatConfig.GetValueArray("monthGenitiveNames", "monthGenitiveName");
				if(monthGenitiveNames.Length > 0) {
					try {
						cultureInfo.DateTimeFormat.MonthGenitiveNames = monthGenitiveNames;
					} catch(ArgumentException ex) {
						throw new ConfigurationException(string.Format("[{0}/monthGenitiveNames] {1}", dateTimeFormatConfigKey, ex.Message));
					}
				}

				string[] abbreviatedDayNames = dateTimeFormatConfig.GetValueArray("abbreviatedDayNames", "abbreviatedDayName");
				if(abbreviatedDayNames.Length > 0) {
					try {
						cultureInfo.DateTimeFormat.AbbreviatedDayNames = abbreviatedDayNames;
					} catch(ArgumentException ex) {
						throw new ConfigurationException(string.Format("[{0}/abbreviatedDayNames] {1}", dateTimeFormatConfigKey, ex.Message));
					}
				}

				string[] shortestDayNames = dateTimeFormatConfig.GetValueArray("shortestDayNames", "shortestDayName");
				if(shortestDayNames.Length > 0) {
					try {
						cultureInfo.DateTimeFormat.ShortestDayNames = shortestDayNames;
					} catch(ArgumentException ex) {
						throw new ConfigurationException(string.Format("[{0}/shortestDayNames] {1}", dateTimeFormatConfigKey, ex.Message));
					}
				}

				string[] abbreviatedMonthNames = dateTimeFormatConfig.GetValueArray("abbreviatedMonthNames", "abbreviatedMonthName");
				if(abbreviatedMonthNames.Length > 0) {
					try {
						cultureInfo.DateTimeFormat.AbbreviatedMonthNames = abbreviatedMonthNames;
					} catch(ArgumentException ex) {
						throw new ConfigurationException(string.Format("[{0}/abbreviatedMonthNames] {1}", dateTimeFormatConfigKey, ex.Message));
					}
				}

				string[] dayNames = dateTimeFormatConfig.GetValueArray("dayNames", "dayName");
				if(dayNames.Length > 0) {
					try {
						cultureInfo.DateTimeFormat.DayNames = dayNames;
					} catch(ArgumentException ex) {
						throw new ConfigurationException(string.Format("[{0}/dayNames] {1}", dateTimeFormatConfigKey, ex.Message));
					}
				}


				string[] monthNames = dateTimeFormatConfig.GetValueArray("monthNames", "monthName");
				if(monthNames.Length > 0) {
					try {
						cultureInfo.DateTimeFormat.MonthNames = monthNames;
					} catch(ArgumentException ex) {
						throw new ConfigurationException(string.Format("[{0}/monthNames] {1}", dateTimeFormatConfigKey, ex.Message));
					}
				}

				if(dateTimeFormatConfig.ContainsKey("calendarWeekRule")) {
					try {
						cultureInfo.DateTimeFormat.CalendarWeekRule = (CalendarWeekRule)Enum.Parse(typeof(CalendarWeekRule), dateTimeFormatConfig.GetValue("calendarWeekRule"), true);
					} catch(ArgumentException) {
						throw new ConfigurationException(string.Format("Value [{0}/calendarWeekRule] is not of type CalendarWeekRule", dateTimeFormatConfigKey));
					}
				}

				if(dateTimeFormatConfig.ContainsKey("firstDayOfWeek")) {
					try {
						cultureInfo.DateTimeFormat.FirstDayOfWeek = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), dateTimeFormatConfig.GetValue("firstDayOfWeek"), true);
					} catch(ArgumentException) {
						throw new ConfigurationException(string.Format("Value [{0}/firstDayOfWeek] is not of type DayOfWeek", dateTimeFormatConfigKey));
					}
//.........這裏部分代碼省略.........
開發者ID:aelveborn,項目名稱:njupiter,代碼行數:101,代碼來源:ConfigurableCultureHandler.cs


注:本文中的System.Globalization.CultureInfo.Clone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。