ProjectArcade

Форк
0
77 строк · 3.0 Кб
1
using System;
2

3
namespace DokanNet
4
{
5
    /// <summary>
6
    /// Provide support to format object with <c>null</c>.
7
    /// </summary>
8
    public class FormatProviders : IFormatProvider, ICustomFormatter
9
    {
10
        /// <summary>
11
        /// A Singleton instance of this class.
12
        /// </summary>
13
        public static readonly FormatProviders DefaultFormatProvider = new FormatProviders();
14

15
        /// <summary>
16
        /// A constant string that represents what to use if the formated object is <c>null</c>.
17
        /// </summary>
18
        public const string NullStringRepresentation = "<null>";
19

20
        /// <summary>
21
        /// Prevents a default instance of the <see cref="FormatProviders"/> class from being created. 
22
        /// </summary>
23
        private FormatProviders()
24
        {
25
        }
26

27
        /// <summary>
28
        /// Format a <see cref="FormattableString"/> using <see cref="DefaultFormatProvider"/>.
29
        /// </summary>
30
        /// <param name="formattable">The <see cref="FormattableString"/> to format.</param>
31
        /// <returns>The formated string.</returns>
32
#pragma warning disable 3001
33
        public static string DokanFormat(string formattable)
34
        {
35
            return formattable; //.ToString(DefaultFormatProvider);
36
        }
37
#pragma warning restore 3001
38

39
        /// <summary>
40
        /// Returns an object that provides formatting services for the
41
        /// specified type.
42
        /// </summary>
43
        /// <returns>An instance of the object specified by 
44
        /// <paramref name="formatType" />, if the 
45
        /// <see cref="T:System.IFormatProvider" /> implementation can supply
46
        /// that type of object; otherwise, <c>null</c>.</returns>
47
        /// <param name="formatType">An object that specifies the type of format
48
        /// object to return. </param>
49
        public object GetFormat(Type formatType)
50
        {
51
            return formatType == typeof(ICustomFormatter) ? this : null;
52
        }
53

54
        /// <summary>
55
        /// Converts the value of a specified object to an equivalent string
56
        /// representation using specified format and culture-specific
57
        /// formatting information.
58
        /// </summary>
59
        /// <returns>The string representation of the value of 
60
        /// <paramref name="arg" />, formatted as specified by 
61
        /// <paramref name="format" /> and <paramref name="formatProvider" />.
62
        /// </returns>
63
        /// <param name="format">A format string containing formatting
64
        /// specifications. </param>
65
        /// <param name="arg">An object to format. </param>
66
        /// <param name="formatProvider">An object that supplies format
67
        /// information about the current instance. </param>
68
        public string Format(string format, object arg, IFormatProvider formatProvider)
69
        {
70
            if (arg == null) 
71
                return NullStringRepresentation;
72

73
            var formattable = arg as IFormattable;
74
            return formattable != null ? formattable.ToString(format, formatProvider) : arg.ToString();
75
        }
76
    }
77
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.