選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CustomProperty.cs 3.6KB

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