C# (CSharp) Class System.Globalization. CultureInfo Code Examples

C# (CSharp) System.Globalization.CultureInfo - 30 examples found. These are the top rated real world C# (CSharp) examples of class System.Globalization.CultureInfo extracted from open source projects. You can rate examples to help us improve the quality of examples
Example #1
0
 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";
     }
 }
Example #2
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            var numberAsString = value as string;
            if (string.IsNullOrEmpty(numberAsString))
            {
                return this.AllowsEmpty
                    ? new ValidationResult(true, null)
                    : new ValidationResult(false, "値を入力してください。");
            }

            int number;
            try
            {
                number = int.Parse(numberAsString);
            }
            catch (Exception)
            {
                return new ValidationResult(false, "数値を入力してください。");
            }

            if (this.Min.HasValue && number < this.Min)
            {
                return new ValidationResult(false, string.Format("{0} 以上の数値を入力してください。", this.Min));
            }

            if (this.Max.HasValue && this.Max < number)
            {
                return new ValidationResult(false, string.Format("{0} 以下の数値を入力してください。", this.Max));
            }

            return new ValidationResult(true, null);
        }
	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;
	}
Example #4
0
        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)));
        }
        /// <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);
        }
Example #6
0
 // ----------------------------------------------------------------------
 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;
 }
        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;*/
        }
        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);
        }
 /// <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;
 }
        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;
        }
 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;
 }
	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;
	}
Example #13
0
        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;
            }
        }
        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]);
            }
        }
Example #15
0
        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];
        }
        public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
        {
            if ( value == null ) return null;

            if ( value.GetType() == typeof( System.Net.IPAddress ) ) return ( ( System.Net.IPAddress ) value ).ToString();
            return String.Empty;
        }
Example #17
0
 public static Task CreateTaskByTable(DataTable dt)
 {
     Task task = null;
     try
     {
         task = new Task();
         task.TaskNo = (dt.Rows[0]["TaskNo"] == null ? "" : dt.Rows[0]["TaskNo"].ToString());
         task.BatchNo = (dt.Rows[0]["BatchNo"] == null ? "" : dt.Rows[0]["BatchNo"].ToString());
         task.ItemNo = (dt.Rows[0]["ItemNo"] == null ? "" : dt.Rows[0]["ItemNo"].ToString());
         task.ItemName = (dt.Rows[0]["ItemName"] == null ? "" : dt.Rows[0]["ItemName"].ToString());
         task.Sn = (dt.Rows[0]["Sn"] == null ? "" : dt.Rows[0]["Sn"].ToString());
         task.PV = (dt.Rows[0]["PV"] == null ? 0 : int.Parse(dt.Rows[0]["PV"].ToString()));
         task.Result = (dt.Rows[0]["Result"] == null ? 0 : int.Parse(dt.Rows[0]["Result"].ToString()));
         task.redundantVaue = (dt.Rows[0]["RedundantVaue"] == null ? 0 : int.Parse(dt.Rows[0]["RedundantVaue"].ToString()));
         IFormatProvider ifp = new CultureInfo("zh-CN", true);
         if (dt.Rows[0]["StartTime"] != null)
         {
             DateTime.TryParseExact(dt.Rows[0]["StartTime"].ToString(), DateTimeFormat2, ifp, DateTimeStyles.None, out task.StartTime);
         }
         if (dt.Rows[0]["CompleteTime"] != null)
         {
             DateTime.TryParseExact(dt.Rows[0]["CompleteTime"].ToString(), DateTimeFormat2, ifp, DateTimeStyles.None, out task.CompleteTime);
         }
         return task;
     }
     catch (Exception ex)
     {
         Program.WriteErrorLog("CreateTaskByTable", ex);
         return task;
     }
 }
Example #18
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     var format = parameter as string;
     if (format == "B")
         return ConvertUnit(value, CommonLocale.B, 1024, "", CommonLocale.ki, CommonLocale.Mi, CommonLocale.Gi);
     return value;
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return TimeConverter.ConvertDoubleToTime(value, targetType, parameter, culture);
            /*if (value is Double)
            {
                Double d = (Double)value;
                TimePart timePart = TimeConverter.GetTimePart(parameter, culture);

                if (targetType == typeof(TimeSpan))
                {
                    return TimeConverter.DoubleToTimeSpan(d, timePart);
                }

                if (targetType == typeof(Duration))
                {
                    return TimeConverter.DoubleToDuration(d, timePart);
                }

                if (targetType == typeof(DateTime))
                {
                    return TimeConverter.DoubleToDateTime(d, timePart);
                }
            }

            return DependencyProperty.UnsetValue;*/
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is bool)) return DependencyProperty.UnsetValue;
            bool visible = ((bool)value) ^ VisibleWhenFalse;

            return visible ? Visibility.Visible : Visibility.Collapsed;
        }
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value == null) return null;

			double rankNumber = 0;
			if (value is string)
			{
				rankNumber = double.Parse((string) value);
			}
			else
			{
				rankNumber = System.Convert.ToDouble(value);
			}

			if (rankNumber >= 1 && rankNumber < 2) return new Uri("/resources/images/ranks/elo01.png", UriKind.Relative);
			if (rankNumber >= 2 && rankNumber < 3) return new Uri("/resources/images/ranks/elo02.png", UriKind.Relative);
			if (rankNumber >= 3 && rankNumber < 4) return new Uri("/resources/images/ranks/elo03.png", UriKind.Relative);
			if (rankNumber >= 4 && rankNumber < 5) return new Uri("/resources/images/ranks/elo04.png", UriKind.Relative);
			if (rankNumber >= 5 && rankNumber < 6) return new Uri("/resources/images/ranks/elo05.png", UriKind.Relative);
			if (rankNumber >= 6 && rankNumber < 7) return new Uri("/resources/images/ranks/elo06.png", UriKind.Relative);
			if (rankNumber >= 7 && rankNumber < 8) return new Uri("/resources/images/ranks/elo07.png", UriKind.Relative);
			if (rankNumber >= 8 && rankNumber < 9) return new Uri("/resources/images/ranks/elo08.png", UriKind.Relative);
			if (rankNumber >= 9 && rankNumber < 10) return new Uri("/resources/images/ranks/elo09.png", UriKind.Relative);
			if (rankNumber >= 10 && rankNumber < 11) return new Uri("/resources/images/ranks/elo10.png", UriKind.Relative);
			if (rankNumber >= 11 && rankNumber < 12) return new Uri("/resources/images/ranks/elo11.png", UriKind.Relative);
			if (rankNumber >= 12 && rankNumber < 13) return new Uri("/resources/images/ranks/elo12.png", UriKind.Relative);
			if (rankNumber >= 13 && rankNumber < 14) return new Uri("/resources/images/ranks/elo13.png", UriKind.Relative);
			if (rankNumber >= 14 && rankNumber < 15) return new Uri("/resources/images/ranks/elo14.png", UriKind.Relative);
			if (rankNumber >= 15 && rankNumber < 16) return new Uri("/resources/images/ranks/elo15.png", UriKind.Relative);
			if (rankNumber >= 16 && rankNumber < 17) return new Uri("/resources/images/ranks/elo16.png", UriKind.Relative);
			if (rankNumber >= 17 && rankNumber < 18) return new Uri("/resources/images/ranks/elo17.png", UriKind.Relative);
			if (rankNumber >= 18) return new Uri("/resources/images/ranks/elo18.png", UriKind.Relative);
			return new Uri("/resources/images/ranks/no_rank.png", UriKind.Relative);
		}
Example #22
0
	// Overrides the ConvertTo method of TypeConverter.
	public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
		var v = value as IEnumerable<String>;
		if (destinationType == typeof(string)) {
			return string.Join(", ", v.Select(AddQuotes).ToArray());
		}
		return base.ConvertTo(context, culture, value, destinationType);
	}
 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 Visibility.Visible;
     }
     else
     {
         return Visibility.Collapsed;
     }
 }
Example #24
0
	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);
	}
Example #25
0
	/// <summary>
	/// Constructor specifying both the IPublishedContent and the CultureInfo
	/// </summary>
	/// <param name="content"></param>
	/// <param name="culture"></param>
	public RenderModel(IPublishedContent content, CultureInfo culture)
	{
           if (content == null) throw new ArgumentNullException("content");
		if (culture == null) throw new ArgumentNullException("culture");
		Content = content;
		CurrentCulture = culture;
	}
        /// <summary>
        /// Converts a value.
        /// </summary>
        /// <param name="value">The value that is produced by the binding target.</param>
        /// <param name="targetType">The type to convert to.</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 <c>null</c>, the valid <c>null</c> value is used.
        /// </returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var b = (bool)value;
            if (b != this.NullValue)
            {
                var ult = Nullable.GetUnderlyingType(targetType);
                if (ult != null)
                {
                    if (ult == typeof(DateTime))
                    {
                        return DateTime.Now;
                    }

                    return Activator.CreateInstance(ult);
                }

                if (targetType == typeof(string))
                {
                    return string.Empty;
                }

                return Activator.CreateInstance(targetType);
            }

            if (targetType == typeof(double))
            {
                return double.NaN;
            }

            return null;
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType != typeof(bool))
                throw new InvalidOperationException("The target must be boolean.");

            return !(bool)value;
        }
 public object Convert(object value, Type targetType,
     object parameter, CultureInfo culture)
 {
     if ((bool) value)
         return "true";
     return "false";
 }
    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);

        // Check security
        CheckSecurity();

        // Set cultures
        SetCulture();
        IFormatProvider culture = DateTimeHelper.DefaultIFormatProvider;
        IFormatProvider currentCulture = new CultureInfo(Thread.CurrentThread.CurrentUICulture.IetfLanguageTag);

        // Get report info
        string reportName = ValidationHelper.GetString(Request.QueryString["reportname"], "");
        ReportInfo report = ReportInfoProvider.GetReportInfo(reportName);

        if (report != null)
        {
            // Get report parameters
            string parameters = QueryHelper.GetString("parameters", "");
            DataRow drParameters = ReportHelper.GetReportParameters(report, parameters, AnalyticsHelper.PARAM_SEMICOLON, culture, currentCulture);

            // Init report
            if (drParameters != null)
            {
                DisplayReport1.LoadFormParameters = false;
                DisplayReport1.ReportParameters = drParameters;
            }

            DisplayReport1.ReportName = report.ReportName;
            DisplayReport1.DisplayFilter = false;

            Page.Title = GetString("Report_Print.lblPrintReport") + " " + HTMLHelper.HTMLEncode(report.ReportDisplayName);
        }
    }
Example #30
0
        private CultureInfo alteraCulturaThread(bool ponto)
        {
            //Passar para o Frmk - Gustavo.
            System.Globalization.CultureInfo obj = null;

            try
            {
                if (ponto)
                {
                    obj = new System.Globalization.CultureInfo("PT-BR", true);
                    obj.NumberFormat.CurrencyGroupSeparator = ",";
                    obj.NumberFormat.CurrencyDecimalSeparator = ".";
                    obj.NumberFormat.NumberGroupSeparator = ",";
                    obj.NumberFormat.NumberDecimalSeparator = ".";
                    System.Threading.Thread.CurrentThread.CurrentCulture = obj;
                }
                else
                {
                    obj = new System.Globalization.CultureInfo("PT-BR", true);
                    obj.NumberFormat.CurrencyGroupSeparator = ".";
                    obj.NumberFormat.CurrencyDecimalSeparator = ",";
                    obj.NumberFormat.NumberGroupSeparator = ".";
                    obj.NumberFormat.NumberDecimalSeparator = ",";
                    System.Threading.Thread.CurrentThread.CurrentCulture = obj;
                }
            }
            catch (Exception ex)
            {
                obj = null;

            }

            return obj;
        }