本文整理汇总了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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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]);
}
示例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);
}
}
示例8: CloneNeutral
[Test] // bug #77347
public void CloneNeutral ()
{
CultureInfo culture = new CultureInfo ("en");
CultureInfo cultureClone = culture.Clone () as CultureInfo;
Assert.IsTrue (culture.Equals (cultureClone));
}
示例9: TestClone
public void TestClone()
{
CultureInfo myCultureInfo = new CultureInfo("fr-FR");
CultureInfo myClone = myCultureInfo.Clone() as CultureInfo;
Assert.True(myClone.Equals(myCultureInfo));
}
示例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;
}
}
示例11: Clone
public void Clone ()
{
TextInfo enus = new CultureInfo ("en-US").TextInfo;
TextInfo clone = (TextInfo) enus.Clone ();
CompareProperties (enus, clone, true);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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));
}
//.........这里部分代码省略.........