public static string Format(bool value, FormatAttrib param)
            {
                if (param != null)
                {
                    switch (param.Formats)
                    {
                    case Formats.TrueFalse:
                        return(value.ToString());

                    case Formats.YesNo:
                        return(value ? YesString : NoString);

                    case Formats.Values:
                        var values = param.Values;
                        if (values == null)
                        {
                            throw new ArgumentNullException("param.Values");
                        }
                        if (values.Length != 2)
                        {
                            throw new ArgumentOutOfRangeException("param.Values");
                        }
                        return(value ? values[0] : values[1]);

                    default:
                        throw new InvalidOperationException();
                    }
                }
                return(value ? YesString : NoString);
            }
            public static string Format(int value, FormatAttrib param)
            {
                if (param != null)
                {
                    switch (param.Formats)
                    {
                    case Formats.Comma:
                        return(value.ToString("#,##0", CultureInfo.InvariantCulture));

                    case Formats.Byte:
                        int length = (int)Math.Floor((double)(value.ToString(CultureInfo.InvariantCulture).Length - 1) / 3);
                        if (length > 0)
                        {
                            return(Math.Round((double)value / (2 << (10 * length)), 2).ToString(CultureInfo.InvariantCulture) + " " + "  KBMBGB".Substring(length * 2, 2));
                        }
                        if (value == 1)
                        {
                            return("1 byte");
                        }
                        return(value.ToString(CultureInfo.InvariantCulture) + " bytes");

                    case Formats.Pattern:
                        return(value.ToString(param.Format, CultureInfo.InvariantCulture));

                    default:
                        throw new InvalidOperationException();
                    }
                }
                return(value.ToString(CultureInfo.InvariantCulture));
            }
 public static string Format(ZipStruct value, FormatAttrib param)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     return(value.Text);
 }
            public static string Format(DateTime value, FormatAttrib param)
            {
                if (param != null)
                {
                    switch (param.Formats)
                    {
                    case Formats.Pattern:
                        return(value.ToString(param.Format, CultureInfo.InvariantCulture));

                    default:
                        throw new InvalidOperationException();
                    }
                }
                return(value.ToString("M/d", CultureInfo.InvariantCulture));
            }
Exemplo n.º 5
0
            public static string Format(string value, FormatAttrib param)
            {
                if (param != null)
                {
                    switch (param.Formats)
                    {
                    case Formats.Last4:
                        int valueLength = value.Length;
                        return(valueLength > 4 ? new string('*', valueLength - 4) + value.Substring(valueLength - 4) : value);

                    default:
                        throw new InvalidOperationException();
                    }
                }
                return(value);
            }
            public static string Format(DateTime value, FormatAttrib param)
            {
                if (param != null)
                {
                    switch (param.Formats)
                    {
                    case Formats.Date:
                        return(value.ToString("dd MMMM yyyy hh:mm tt", CultureInfo.InvariantCulture));

                    case Formats.LongDateTime:
                        return(value.ToString("dddd, MMMM d, yyyy hh:mm:ss tt", CultureInfo.InvariantCulture));

                    case Formats.LongDate:
                        return(value.ToString("dddd, MMMM d, yyyy", CultureInfo.InvariantCulture));

                    case Formats.LongTime:
                        return(value.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture));

                    case Formats.ShortDate:
                        return(value.ToString("d-MMM-yyyy", CultureInfo.InvariantCulture));

                    case Formats.ShortDateTime:
                        return(value.ToString("d-MMM-yyyy hh:mm tt", CultureInfo.InvariantCulture));

                    case Formats.ShortTime:
                        return(value.ToString("hh:mm tt", CultureInfo.InvariantCulture));

                    case Formats.TinyDate:
                        return(value.ToString("M/d/yy", CultureInfo.InvariantCulture));

                    case Formats.TinyDateTime:
                        return(value.ToString("M/d/yy hh:mm tt", CultureInfo.InvariantCulture));

                    case Formats.Pattern:
                        return(value.ToString(param.Format, CultureInfo.InvariantCulture));

                    default:
                        throw new InvalidOperationException();
                    }
                }
                return(value.ToString("M/d/yyyy hh:mm tt", CultureInfo.InvariantCulture));
            }
Exemplo n.º 7
0
            public static string Format(DateTime value, FormatAttrib param)
            {
                if (param != null)
                {
                    switch (param.Formats)
                    {
                    case Formats.Date:
                        return(value.ToString("dd MMMM yyyy", CultureInfo.InvariantCulture));

                    case Formats.LongDate:
                        return(value.ToString("dddd, MMMM d, yyyy", CultureInfo.InvariantCulture));

                    case Formats.LongDate2:
                        return(value.ToString((value.Year == DateTime.Today.Year ? "dddd, MMMM d" : "dddd, MMMM d, yyyy"), CultureInfo.InvariantCulture));

                    case Formats.ShortDate:
                        return(value.ToString("d-MMM-yyyy", CultureInfo.InvariantCulture));

                    case Formats.ShorterDate:
                        return(CultureInfo.InvariantCulture.DateTimeFormat.AbbreviatedMonthNames[value.Month - 1] + ". " + value.Day + ", " + value.Year);

                    case Formats.MonthDay:
                        return(CultureInfo.InvariantCulture.DateTimeFormat.MonthNames[value.Month - 1] + " " + value.Day);

                    case Formats.MonthYear:
                        return(CultureInfo.InvariantCulture.DateTimeFormat.MonthNames[value.Month - 1] + " " + value.Year);

                    case Formats.Pattern:
                        return(value.ToString(param.Format, CultureInfo.InvariantCulture));

                    default:
                        throw new InvalidOperationException();
                    }
                }
                return(value.ToString("M/d/yyyy", CultureInfo.InvariantCulture));
            }
Exemplo n.º 8
0
 public static string Format(string value, FormatAttrib param)
 {
     return(value);
 }