コード例 #1
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || !(value is int))
            {
                return(DependencyProperty.UnsetValue);
            }

            int age   = (int)value;
            var index = PluralsHelper.GetPluralEnding(age);

            return(PluralsHelper.years[index]);
        }
コード例 #2
0
        /// <summary>
        /// Unit of DateOffset with ending for given offset.
        /// </summary>
        public static string GetUnitString(int?offset, DateUnit unit)
        {
            if (offset == null)
            {
                offset = 0;
            }

            int ending = PluralsHelper.GetPluralEnding(offset.Value);

            switch (unit)
            {
            case DateUnit.Day: return(Plurals.days[ending]);

            case DateUnit.Week: return(Plurals.weeks[ending]);

            case DateUnit.Month: return(Plurals.months[ending]);

            case DateUnit.Year: return(Plurals.years[ending]);
            }
            throw new ArgumentOutOfRangeException("unit");
        }