jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
 
namespace Novacode
{
    public class CustomProperty
    {
        private string name;
        private object value;
        private string type;
 
        /// <summary>
        /// The name of this CustomProperty.
        /// </summary>
        public string Name { get { return name;} }
 
        /// <summary>
        /// The value of this CustomProperty.
        /// </summary>
        public object Value { get { return value; } }
 
        internal string Type { get { return type; } }
 
        internal CustomProperty(string name, string type, string value)
        {
            object realValue;
            switch (type)
            {
                case "lpwstr": 
                {
                    realValue = value;
                    break;
                }
 
                case "i4":
                {
                    realValue = int.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                    break;
                }
 
                case "r8":
                {
                    realValue = Double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                    break;
                }
 
                case "filetime":
                {
                    realValue = DateTime.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                    break;
                }
 
                case "bool":
                {
                    realValue = bool.Parse(value);
                    break;
                }
 
                default: throw new Exception();
            }
 
            this.name = name;
            this.type = type;
            this.value = realValue;
        }
 
        private CustomProperty(string name, string type, object value)
        {
            this.name = name;
            this.type = type;
            this.value = value;
        }
 
        /// <summary>
        /// Create a new CustomProperty to hold a string.
        /// </summary>
        /// <param name="name">The name of this CustomProperty.</param>
        /// <param name="value">The value of this CustomProperty.</param>
        public CustomProperty(string name, string value) : this(name, "lpwstr", value as object) { }
 
 
        /// <summary>
        /// Create a new CustomProperty to hold an int.
        /// </summary>
        /// <param name="name">The name of this CustomProperty.</param>
        /// <param name="value">The value of this CustomProperty.</param>
        public CustomProperty(string name, int value) : this(name, "i4", value as object) { }
 
 
        /// <summary>
        /// Create a new CustomProperty to hold a double.
        /// </summary>
        /// <param name="name">The name of this CustomProperty.</param>
        /// <param name="value">The value of this CustomProperty.</param>
        public CustomProperty(string name, double value) : this(name, "r8", value as object) { }
 
 
        /// <summary>
        /// Create a new CustomProperty to hold a DateTime.
        /// </summary>
        /// <param name="name">The name of this CustomProperty.</param>
        /// <param name="value">The value of this CustomProperty.</param>
        public CustomProperty(string name, DateTime value) : this(name, "filetime", value.ToUniversalTime() as object) { }
 
        /// <summary>
        /// Create a new CustomProperty to hold a bool.
        /// </summary>
        /// <param name="name">The name of this CustomProperty.</param>
        /// <param name="value">The value of this CustomProperty.</param>
        public CustomProperty(string name, bool value) : this(name, "bool", value as object) { }
    }
}