本文整理汇总了C#中System.Globalization.CultureInfo类的典型用法代码示例。如果您正苦于以下问题:C# CultureInfo类的具体用法?C# CultureInfo怎么用?C# CultureInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CultureInfo类属于System.Globalization命名空间,在下文中一共展示了CultureInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var flag = false;
if (value is bool)
{
flag = (bool)value;
}
else if (value is bool?)
{
var nullable = (bool?)value;
flag = nullable.GetValueOrDefault();
}
if (parameter != null)
{
if (bool.Parse((string)parameter))
{
flag = !flag;
}
}
if (flag)
{
return "/Resources/Images/License_Valid.png";
}
else
{
return "/Resources/Images/License_Invalid.png";
}
}
示例2: ConvertFrom
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
if (value is string) {
var vs = ((string)value).Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
return vs.Select(v => v.Trim('"')).ToList();
}
return base.ConvertFrom(context, culture, value);
}
示例3: ConvertTo
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (context == null)
return null;
var p = context.GetService (typeof (IXamlNameProvider)) as IXamlNameProvider;
return p != null ? p.GetName (value) : null;
}
示例4: Ctor_CultureInfo
public static void Ctor_CultureInfo(object a, object b, int expected)
{
var culture = new CultureInfo("en-US");
var comparer = new Comparer(culture);
Assert.Equal(expected, Math.Sign(comparer.Compare(a, b)));
}
示例5: Convert
/// <summary>
/// Converts the source value to a target value.
/// </summary>
/// <param name="value">The source value to convert.</param>
/// <param name="targetType">The type of the target property.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>
/// A converted value. If the method returns null, the valid null value is used.
/// </returns>
/// <remarks>
/// This method will only be called if the mode of the <see cref="SingleSourceBinding"/> is either <see cref="BindingMode.TwoWay"/>
/// or <see cref="BindingMode.OneWayToTarget"/>.
/// </remarks>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof (string))
return value;
return ((DateTime) value).ToString("d", culture);
}
示例6: TimeFormatter
// ----------------------------------------------------------------------
public TimeFormatter( CultureInfo culture = null,
string contextSeparator = "; ", string startEndSeparator = " - ",
string durationSeparator = " | ",
string dateTimeFormat = null,
string shortDateFormat = null,
string longTimeFormat = null,
string shortTimeFormat = null,
DurationFormatType durationType = DurationFormatType.Compact,
bool useDurationSeconds = false,
bool useIsoIntervalNotation = false)
{
if ( culture == null )
{
culture = CultureInfo.CurrentCulture;
}
this.culture = culture;
listSeparator = culture.TextInfo.ListSeparator;
this.contextSeparator = contextSeparator;
this.startEndSeparator = startEndSeparator;
this.durationSeparator = durationSeparator;
this.dateTimeFormat = dateTimeFormat;
this.shortDateFormat = shortDateFormat;
this.longTimeFormat = longTimeFormat;
this.shortTimeFormat = shortTimeFormat;
this.durationType = durationType;
this.useDurationSeconds = useDurationSeconds;
this.useIsoIntervalNotation = useIsoIntervalNotation;
}
示例7: ConvertBack
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return TimeConverter.ConvertTimeToDouble(value, targetType, parameter, culture);
/*if (targetType == typeof(Double))
{
TimePart timePart = TimeConverter.GetTimePart(parameter, culture);
if (value is TimeSpan)
{
return TimeConverter.TimeSpanToDouble((TimeSpan)value, timePart);
}
if (value is Duration)
{
return TimeConverter.DurationToDouble((Duration)value, timePart);
}
if (value is DateTime)
{
return TimeConverter.DateTimeToDouble((DateTime)value, timePart);
}
}
return DependencyProperty.UnsetValue;*/
}
示例8: ConvertSimple
private object ConvertSimple(Type typeToConvertTo, object value, CultureInfo cultureInfo)
{
if (typeToConvertTo.IsEnum && value is string)
return Enum.Parse(typeToConvertTo, (string)value, true);
return System.Convert.ChangeType(value, typeToConvertTo, cultureInfo);
}
示例9: AuthorizationParameters
/// <summary>
/// </summary>
/// <param name="culture">Текущие сведения о языке и региональных параметрах</param>
/// <param name="authUri">Url авторизации</param>
/// <param name="blankUri">Url на который возвращаются данные авторизации</param>
/// <param name="availableHostNames">Доступные имена хостов в браузере. Если NulL, то доступен переход на любой хост</param>
public AuthorizationParameters(CultureInfo culture, Uri authUri, Uri blankUri, IEnumerable<string> availableHostNames = null)
{
_culture = culture;
_authUri = authUri;
_blankUri = blankUri;
_availableHostNames = availableHostNames;
}
示例10: ConvertBack
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
RepeatType repeatType = RepeatType.NotRepeated;
if (value is int)
{
switch ((int)value)
{
case 0:
repeatType = RepeatType.NotRepeated;
break;
case 1:
repeatType = RepeatType.Daily;
break;
case 2:
repeatType = RepeatType.Weekly;
break;
case 3:
repeatType = RepeatType.Monthly;
break;
case 4:
repeatType = RepeatType.Yearly;
break;
default:
break;
}
}
return repeatType;
}
示例11: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return Visibility.Collapsed;
bool visibility = (bool)value;
return visibility ? Visibility.Collapsed : Visibility.Visible;
}
示例12: Convert
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
ScanStatus s1 = (ScanStatus)value;
ScanStatus s2 = (ScanStatus)parameter;
return s1 == s2 ? Visibility.Visible : Visibility.Collapsed;
}
示例13: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int index = value is int ? (int)value : 0;
int type = parameter is string ? Int32.Parse((string)parameter) : 0;
switch (type)
{
case Background:
if (index % 2 == 0)
{
return MotionFullItemBackgroundEven;
}
return MotionFullItemBackgroundOdd;
case TopSeperator:
if (index % 2 == 0)
{
return MotionFullItemTopSeperatorEven;
}
return MotionFullItemTopSeperatorOdd;
case BottomSeperator:
if (index % 2 == 0)
{
return MotionFullItemBottomSeperatorEven;
}
return MotionFullItemBottomSeperatorOdd;
default:
Debug.Assert(type != 0, "Null type");
return null;
}
}
示例14: Test1
public void Test1()
{
string[] edays = {
"\u661F\u671F\u65E5",
"\u661F\u671F\u4E00",
"\u661F\u671F\u4E8C",
"\u661F\u671F\u4E09",
"\u661F\u671F\u56DB",
"\u661F\u671F\u4E94",
"\u661F\u671F\u516D"
};
string[] emonths = GetMonthNames();
DateTimeFormatInfo dtfi = new CultureInfo("zh-TW").DateTimeFormat;
dtfi.Calendar = new TaiwanCalendar();
// Actual Day Names and Month Names for TaiwanCalendar
string[] adays = dtfi.DayNames;
for (int i = 0; i < edays.Length; i++)
{
Assert.Equal(edays[i], adays[i]);
}
string[] amonths = dtfi.MonthNames;
for (int i = 0; i < edays.Length; i++)
{
Assert.Equal(emonths[i], amonths[i]);
}
}
示例15: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// Parse value into equation and remove spaces
var mathEquation = parameter as string;
mathEquation = mathEquation.Replace(" ", "");
mathEquation = mathEquation.Replace("@VALUE", value.ToString());
// Validate values and get list of numbers in equation
var numbers = new List<double>();
double tmp;
foreach (string s in mathEquation.Split(_allOperators))
{
if (s != string.Empty)
{
if (double.TryParse(s, out tmp))
{
numbers.Add(tmp);
}
else
{
// Handle Error - Some non-numeric, operator, or grouping character found in string
throw new InvalidCastException();
}
}
}
// Begin parsing method
EvaluateMathString(ref mathEquation, ref numbers, 0);
// After parsing the numbers list should only have one value - the total
return numbers[0];
}