本文整理汇总了C#中System.Globalization.RegionInfo类的典型用法代码示例。如果您正苦于以下问题:C# RegionInfo类的具体用法?C# RegionInfo怎么用?C# RegionInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RegionInfo类属于System.Globalization命名空间,在下文中一共展示了RegionInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DotNETFrameworkFallback
/// <summary>
/// Dots the net framework fallback.
/// </summary>
/// <param name="storeAlias">The store alias.</param>
/// <returns></returns>
protected virtual List<Country> DotNETFrameworkFallback(string storeAlias)
{
Store store = StoreHelper.GetByAlias(storeAlias);
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;
if (store != null)
{
Thread.CurrentThread.CurrentCulture = store.CultureInfo;
Thread.CurrentThread.CurrentUICulture = store.CultureInfo;
}
var cultureList = new Dictionary<string, string>();
foreach (var culture in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
var region = new RegionInfo(culture.LCID);
if (!(cultureList.ContainsKey(region.TwoLetterISORegionName)))
cultureList.Add(region.TwoLetterISORegionName, region.DisplayName);
}
List<Country> countries = cultureList.Select(culture => new Country {Name = culture.Value, Code = culture.Key}).Where(country => !string.IsNullOrEmpty(country.Name)).OrderBy(country => country.Name).ToList();
if (store != null)
{
Thread.CurrentThread.CurrentCulture = currentCulture;
Thread.CurrentThread.CurrentUICulture = currentUICulture;
}
return countries;
}
示例2: RegisterCultureBasedOn
public static RegistrationResults RegisterCultureBasedOn(string newCultureCode, string languageCode, string regionCode)
{
var baseCulture = new CultureInfo(languageCode);
var baseRegionInfo = new RegionInfo(regionCode);
return RegisterCultureBasedOn(newCultureCode, baseCulture, baseRegionInfo);
}
示例3: GetCurrencyInfo
/// <summary>
/// Gets the currency information.
/// </summary>
/// <param name="isoCurrency">The iso currency.</param>
/// <returns>The currency</returns>
/// <exception cref="System.ArgumentException"></exception>
public static Currency GetCurrencyInfo(string isoCurrency)
{
var r = GetRegionFromCache(isoCurrency);
if (r == null)
{
foreach (var c in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
var reg = new RegionInfo(c.LCID);
if (String.Compare(isoCurrency, reg.ISOCurrencySymbol, StringComparison.OrdinalIgnoreCase) == 0)
{
var currency = new Currency
{
CurrencyEnglishName = reg.CurrencyEnglishName,
CurrencyNativeName = reg.CurrencyNativeName,
CurrencySymbol = reg.CurrencySymbol,
IsoCurrencySymbol = reg.ISOCurrencySymbol
};
SaveRegionInCache(isoCurrency, currency);
return currency;
}
}
throw new ArgumentException();
}
return r;
}
示例4: RegisterCustomCulture
private static void RegisterCustomCulture(string customCultureName, string parentCultureName)
{
Console.WriteLine("Registering {0}", customCultureName);
try
{
CultureAndRegionInfoBuilder cib =
new CultureAndRegionInfoBuilder(customCultureName, CultureAndRegionModifiers.None);
CultureInfo ci = new CultureInfo(parentCultureName);
cib.LoadDataFromCultureInfo(ci);
RegionInfo ri = new RegionInfo(parentCultureName);
cib.LoadDataFromRegionInfo(ri);
cib.Register();
Console.WriteLine("Success.");
}
catch (InvalidOperationException)
{
// This is OK, means that this is already registered.
Console.WriteLine("The custom culture {0} was already registered", customCultureName);
}
catch (Exception ex)
{
Console.WriteLine("Registering the custom culture {0} failed", customCultureName);
Console.WriteLine(ex);
}
Console.WriteLine();
}
示例5: PopulateCurrencies
private void PopulateCurrencies()
{
List<ListItem> items = new List<ListItem>();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
if (ci.IsNeutralCulture != true)
{
RegionInfo region = new RegionInfo(ci.LCID);
string currencyName = region.CurrencyEnglishName;
string currencySymbol = region.CurrencySymbol;
string format = string.Format("{0} [{1}]", currencyName, currencySymbol);
ListItem item = new ListItem();
item.Text = format;
item.Value = format;
// Add to our list
if (!items.Contains(item))
items.Add(item);
}
}
// Sort array
items = items.OrderBy(li => li.Text).ToList();
// Add to our list
ddlCurrenciesSymbol.Items.AddRange(items.ToArray());
}
示例6: CalculateShippingCost
public decimal CalculateShippingCost(float packageWeightInKilograms, Size<float> packageDimensionsInInches, RegionInfo destination)
{
Contract.Requires<ArgumentOutOfRangeException>(packageWeightInKilograms > 0f, "Package weight must be positive and non-zero");
Contract.Requires<ArgumentOutOfRangeException>(packageDimensionsInInches.X > 0f && packageDimensionsInInches.Y > 0f, "Package dimensions must be positive and non-zero");
return decimal.MinusOne;
}
示例7: PopulateCurrencies
/// <summary>
/// Populates the list of currencies
/// </summary>
private void PopulateCurrencies()
{
ddlCurrencySymbol.Items.Clear();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
if (!ci.IsNeutralCulture)
{
RegionInfo region = new RegionInfo(ci.LCID);
ListItem item = new ListItem();
item.Value = region.CurrencySymbol;
item.Text = string.Format("{0} [{1}]", region.CurrencyNativeName, region.CurrencySymbol);
ddlCurrencySymbol.Items.Add(item);
}
}
// Select the current culture
RegionInfo currentRegion = new RegionInfo(CultureInfo.CurrentCulture.LCID);
if (currentRegion != null)
{
ListItem item = ddlCurrencySymbol.Items.FindByValue(currentRegion.CurrencySymbol);
if (item != null)
ddlCurrencySymbol.SelectedValue = item.Value;
}
}
示例8: TestCreationOfBasicMoney
public void TestCreationOfBasicMoney()
{
var currentSymbol = CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol;
var currentRegion = new RegionInfo(CultureInfo.CurrentCulture.LCID);
var currentCode = currentRegion.ISOCurrencySymbol;
var currentEnglishName = currentRegion.CurrencyEnglishName;
var currentDigits = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits;
//Locale specific formatting
var money1 = new Money(2000.1234567m, CurrencyCodes.USD);
Assert.AreEqual("$2,000.12", money1.ToString());
//Default currency
var money2 = new Money(3000m);
Assert.AreEqual(currentCode, money2.CurrencyCode);
Assert.AreEqual(currentSymbol, money2.CurrencySymbol);
Assert.AreEqual(currentEnglishName, money2.CurrencyName);
Assert.AreEqual(currentDigits, money2.DecimalDigits);
//Implicit casting of int, decimal and double to Money
var money3 = new Money(5.0d);
var money4 = new Money(5.0m);
var money5 = new Money(5);
Money money6 = 5.0d;
Money money7 = 5.0m;
Money money8 = 5;
Money money9 = 5.0f;
Money money10 = 5.0;
Assert.IsTrue(money3 == money4 && money4 == money5 && money5 == money6 && money6 == money7 && money7 == money8 && money8 == money9 && money9 == money10);
//Generic 3char currency code formatting instead of locale based with symbols
Assert.AreEqual("USD2,000", money1.ToString(true));
}
示例9: GetCountryList
public static IEnumerable<RegionInfo> GetCountryList()
{
//create a new Generic list to hold the country names returned
Dictionary<string, RegionInfo> regions = new Dictionary<string, RegionInfo>();
//create an array of CultureInfo to hold all the cultures found, these include the users local cluture, and all the
//cultures installed with the .Net Framework
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
//loop through all the cultures found
foreach (CultureInfo culture in cultures)
{
//pass the current culture's Locale ID (http://msdn.microsoft.com/en-us/library/0h88fahh.aspx)
//to the RegionInfo contructor to gain access to the information for that culture
RegionInfo region = new RegionInfo(culture.LCID);
//make sure out generic list doesnt already
//contain this country
if (!(regions.ContainsKey(region.EnglishName)))
//not there so add the EnglishName (http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.englishname.aspx)
//value to our generic list
regions.Add(region.EnglishName, region);
}
return regions.Values;
}
示例10: FormatCurrency
public string FormatCurrency(decimal amount, Currency targetCurrency, bool includeSymbol = true)
{
//find out the culture for the target currency
var culture = CultureInfo.GetCultures(CultureTypes.SpecificCultures).FirstOrDefault(c =>
{
var r = new RegionInfo(c.LCID);
return string.Equals(r.ISOCurrencySymbol, targetCurrency.CurrencyCode, StringComparison.CurrentCultureIgnoreCase);
});
//the format of display
var format = targetCurrency.DisplayFormat;
var locale = targetCurrency.DisplayLocale;
if (culture == null)
{
if (!string.IsNullOrEmpty(locale))
{
culture = new CultureInfo(locale);
}
}
if (string.IsNullOrEmpty(format))
{
format = culture == null || !includeSymbol ? "{0:N}" : "{0:C}";
}
return culture == null ? string.Format(format, amount): string.Format(culture, format, amount);
}
示例11: OnInit
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_dlInstalledLanguages = new DropDownList();
foreach (var language in umbraco.cms.businesslogic.language.Language.GetAllAsList())
{
var culture = new CultureInfo(language.CultureAlias);
if (culture.IsNeutralCulture) continue;
var currencyRegion = new RegionInfo(culture.LCID);
var value = language.FriendlyName + " " + currencyRegion.ISOCurrencySymbol + " (" + currencyRegion.CurrencySymbol +
" - " +
currencyRegion.CurrencyEnglishName + ")";
_dlInstalledLanguages.Items.Add(new ListItem(value, language.id.ToString(CultureInfo.InvariantCulture)));
}
_dlInstalledLanguages.SelectedValue = _data.Value.ToString();
var user = User.GetCurrent();
if (!user.IsAdmin())
_dlInstalledLanguages.Enabled = false;
if (ContentTemplateContainer != null) ContentTemplateContainer.Controls.Add(_dlInstalledLanguages);
}
示例12: PosTest3
public void PosTest3()
{
CultureInfo myCultur = new CultureInfo("en-IE");
string culture = myCultur.Name;
RegionInfo myRegInfo = new RegionInfo(culture);
Assert.False(myRegInfo.Name != "en-IE" && myRegInfo.Name != "IE");
}
示例13: CreateCulture
public CreateCultureResponse CreateCulture(CreateCultureRequest request)
{
var response = new CreateCultureResponse();
if (request.Data != null)
{
var culture = CultureInfo.GetCultureInfo(request.Data.Code);
var region = new RegionInfo(culture.LCID);
//locate associted info
var language = Uow.Languages.Get(o => o.Iso3.Equals(culture.ThreeLetterISOLanguageName), null, null).FirstOrDefault();
var country = Uow.Countries.Get(o => o.Iso3.Equals(region.ThreeLetterISORegionName), null, null).FirstOrDefault();
// insert culture
Uow.Cultures.Add(new Culture
{
Id = request.Data.Id,
ParentCultureId = request.Data.ParentCulture.Id,
Code = request.Data.Code,
Language = language ?? new Language { Id = culture.LCID, Iso2 = culture.TwoLetterISOLanguageName, Iso3 = culture.ThreeLetterISOLanguageName, Localizations = new Collection<LanguageLocalized> { new LanguageLocalized { LanguageId = culture.LCID, CultureId = CultureInfo.InvariantCulture.LCID, Name = culture.NativeName } } },
Country = country ?? new Country { Id = region.GeoId, Iso2 = region.TwoLetterISORegionName, Iso3 = region.ThreeLetterISORegionName, Localizations = new Collection<CountryLocalized> { new CountryLocalized { CountryId = region.GeoId, CultureId = CultureInfo.InvariantCulture.LCID, Name = region.NativeName } } },
_localizations = new List<CultureLocalized>
{
new CultureLocalized{ Id = request.Data.Id, CultureId = CultureInfo.InvariantCulture.LCID, Name = request.Data.Name}
},
});
Uow.Commit();
}
else
{
throw new Exception("Cannot create empty element");
}
return response;
}
示例14: PosTest4
public void PosTest4()
{
CultureInfo myCultur = new CultureInfo("en-GB");
string culture = myCultur.Name;
RegionInfo myRegInfo = new RegionInfo(culture);
Assert.True(myRegInfo.Name == "en-GB" || myRegInfo.Name == "GB");
}
示例15: VoucherDetails
public VoucherDetails(string strBarCode)
{
InitializeComponent();
this.BarCode = strBarCode;
txtSiteCode.IsReadOnly = true;
txtEffectiveDate.IsReadOnly = true;
txtExpiryDate.IsReadOnly = true;
txtBarCode.IsReadOnly = true;
txtVoucherType.IsReadOnly = true;
txtPrintedDevice.IsReadOnly = true;
txtRedeemDevice.IsReadOnly = true;
txtVoidDevice.IsReadOnly = true;
txtErrorDevice.IsReadOnly = true;
txtPrintedDate.IsReadOnly = true;
txtRedeemDate.IsReadOnly = true;
txtVoidDate.IsReadOnly = true;
txtAmount.IsReadOnly = true;
txtStatus.IsReadOnly = true;
txtErrorDescription.IsReadOnly = true;
txtIssuedUserName.IsReadOnly = true;
txtRedeemUser.IsReadOnly = true;
txtVoidUser.IsReadOnly = true;
txtRedeemSiteCode.IsReadOnly = true;
string CurrencySymbol = new RegionInfo(CurrentSiteCulture).CurrencySymbol;
lblAmount.Content=lblAmount.Content+" in "+CurrencySymbol+" :";
GetVoucherInformation();
}