using System; namespace Novacode { public class CustomProperty { private string name; private object value; private string type; /// /// The name of this CustomProperty. /// public string Name { get { return name;} } /// /// The value of this CustomProperty. /// 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; } /// /// Create a new CustomProperty to hold a string. /// /// The name of this CustomProperty. /// The value of this CustomProperty. public CustomProperty(string name, string value) : this(name, "lpwstr", value as object) { } /// /// Create a new CustomProperty to hold an int. /// /// The name of this CustomProperty. /// The value of this CustomProperty. public CustomProperty(string name, int value) : this(name, "i4", value as object) { } /// /// Create a new CustomProperty to hold a double. /// /// The name of this CustomProperty. /// The value of this CustomProperty. public CustomProperty(string name, double value) : this(name, "r8", value as object) { } /// /// Create a new CustomProperty to hold a DateTime. /// /// The name of this CustomProperty. /// The value of this CustomProperty. public CustomProperty(string name, DateTime value) : this(name, "filetime", value.ToUniversalTime() as object) { } /// /// Create a new CustomProperty to hold a bool. /// /// The name of this CustomProperty. /// The value of this CustomProperty. public CustomProperty(string name, bool value) : this(name, "bool", value as object) { } } }