You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*************************************************************************************
  2. DocX – DocX is the community edition of Xceed Words for .NET
  3. Copyright (C) 2009-2016 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features and fast professional support,
  7. pick up Xceed Words for .NET at https://xceed.com/xceed-words-for-net/
  8. ***********************************************************************************/
  9. using System;
  10. namespace Xceed.Words.NET
  11. {
  12. public class CustomProperty
  13. {
  14. #region Public Properties
  15. /// <summary>
  16. /// The name of this CustomProperty.
  17. /// </summary>
  18. public string Name
  19. {
  20. get;
  21. private set;
  22. }
  23. /// <summary>
  24. /// The value of this CustomProperty.
  25. /// </summary>
  26. public object Value
  27. {
  28. get;
  29. private set;
  30. }
  31. #endregion
  32. #region Internal Properties
  33. internal string Type
  34. {
  35. get;
  36. private set;
  37. }
  38. #endregion
  39. #region Constructors
  40. /// <summary>
  41. /// Create a new CustomProperty to hold a string.
  42. /// </summary>
  43. /// <param name="name">The name of this CustomProperty.</param>
  44. /// <param name="value">The value of this CustomProperty.</param>
  45. public CustomProperty( string name, string value )
  46. : this( name, "lpwstr", value )
  47. {
  48. }
  49. /// <summary>
  50. /// Create a new CustomProperty to hold an int.
  51. /// </summary>
  52. /// <param name="name">The name of this CustomProperty.</param>
  53. /// <param name="value">The value of this CustomProperty.</param>
  54. public CustomProperty( string name, int value )
  55. : this( name, "i4", value )
  56. {
  57. }
  58. /// <summary>
  59. /// Create a new CustomProperty to hold a double.
  60. /// </summary>
  61. /// <param name="name">The name of this CustomProperty.</param>
  62. /// <param name="value">The value of this CustomProperty.</param>
  63. public CustomProperty( string name, double value )
  64. : this( name, "r8", value )
  65. {
  66. }
  67. /// <summary>
  68. /// Create a new CustomProperty to hold a DateTime.
  69. /// </summary>
  70. /// <param name="name">The name of this CustomProperty.</param>
  71. /// <param name="value">The value of this CustomProperty.</param>
  72. public CustomProperty( string name, DateTime value )
  73. : this( name, "filetime", value.ToUniversalTime() )
  74. {
  75. }
  76. /// <summary>
  77. /// Create a new CustomProperty to hold a bool.
  78. /// </summary>
  79. /// <param name="name">The name of this CustomProperty.</param>
  80. /// <param name="value">The value of this CustomProperty.</param>
  81. public CustomProperty( string name, bool value )
  82. : this( name, "bool", value )
  83. {
  84. }
  85. internal CustomProperty( string name, string type, string value )
  86. {
  87. object realValue;
  88. switch( type )
  89. {
  90. case "lpwstr":
  91. {
  92. realValue = value;
  93. break;
  94. }
  95. case "i4":
  96. {
  97. realValue = int.Parse( value, System.Globalization.CultureInfo.InvariantCulture );
  98. break;
  99. }
  100. case "r8":
  101. {
  102. realValue = Double.Parse( value, System.Globalization.CultureInfo.InvariantCulture );
  103. break;
  104. }
  105. case "filetime":
  106. {
  107. realValue = DateTime.Parse( value, System.Globalization.CultureInfo.InvariantCulture );
  108. break;
  109. }
  110. case "bool":
  111. {
  112. realValue = bool.Parse( value );
  113. break;
  114. }
  115. default:
  116. throw new Exception();
  117. }
  118. this.Name = name;
  119. this.Type = type;
  120. this.Value = realValue;
  121. }
  122. private CustomProperty( string name, string type, object value )
  123. {
  124. this.Name = name;
  125. this.Type = type;
  126. this.Value = value;
  127. }
  128. #endregion
  129. }
  130. }