Пример #1
0
        protected virtual string FormatGroupVersionPart(ApiVersion apiVersion, string format, IFormatProvider formatProvider)
        {
            Arg.NotNull(apiVersion, nameof(apiVersion));
            Arg.NotNullOrEmpty(format, nameof(format));
            Arg.NotNull(formatProvider, nameof(formatProvider));
            Contract.Ensures(!IsNullOrEmpty(Contract.Result <string>()));

            if (apiVersion.GroupVersion == null)
            {
                return(Empty);
            }

            var groupVersion = apiVersion.GroupVersion.Value;

            switch (format[0])
            {
            case 'G':
                // G, GG
                var text = new StringBuilder(groupVersion.ToString(GroupVersionFormat, formatProvider));

                // GG
                if (format.Length == 2)
                {
                    AppendStatus(text, apiVersion.Status);
                }

                return(text.ToString());

            case 'M':
                var month = Calendar.GetMonth(groupVersion);

                switch (format.Length)
                {
                case 1:         // M
                    return(month.ToString(formatProvider));

                case 2:         // MM
                    return(month.ToString("00", formatProvider));

                case 3:         // MMM
                    return(DateTimeFormat.GetAbbreviatedMonthName(month));
                }

                // MMMM*
                return(DateTimeFormat.GetMonthName(month));

            case 'd':
                switch (format.Length)
                {
                case 1:         // d
                    return(Calendar.GetDayOfMonth(groupVersion).ToString(formatProvider));

                case 2:         // dd
                    return(Calendar.GetDayOfMonth(groupVersion).ToString("00", formatProvider));

                case 3:         // ddd
                    return(DateTimeFormat.GetAbbreviatedDayName(Calendar.GetDayOfWeek(groupVersion)));
                }

                // dddd*
                return(DateTimeFormat.GetDayName(Calendar.GetDayOfWeek(groupVersion)));

            case 'y':
                var year = Calendar.GetYear(groupVersion);

                switch (format.Length)
                {
                case 1:         // y
                    return((year % 100).ToString(formatProvider));

                case 2:         // yy
                    return((year % 100).ToString("00", formatProvider));

                case 3:         // yyy
                    return(year.ToString("000", formatProvider));
                }

                // yyyy*
                return(year.ToString(formatProvider));
            }

            return(groupVersion.ToString(format, formatProvider));
        }