Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CustomProperty.cs 3.7KB

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