PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Assets/AWSSDK/src/Services/DynamoDBv2/Custom/DataModel/Attributes.cs

https://gitlab.com/github-cloud-corp/aws-sdk-unity
C# | 397 lines | 149 code | 38 blank | 210 comment | 0 complexity | 9e5b0fe51a0f5eb9e8904df40717c620 MD5 | raw file
  1. //
  2. // Copyright 2014-2015 Amazon.com,
  3. // Inc. or its affiliates. All Rights Reserved.
  4. //
  5. // Licensed under the Amazon Software License (the "License").
  6. // You may not use this file except in compliance with the
  7. // License. A copy of the License is located at
  8. //
  9. // http://aws.amazon.com/asl/
  10. //
  11. // or in the "license" file accompanying this file. This file is
  12. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. // CONDITIONS OF ANY KIND, express or implied. See the License
  14. // for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. using System;
  18. using System.Linq;
  19. namespace Amazon.DynamoDBv2.DataModel
  20. {
  21. /// <summary>
  22. /// Base DynamoDB attribute.
  23. /// </summary>
  24. [AttributeUsage(AttributeTargets.All, Inherited=true, AllowMultiple=false)]
  25. public abstract class DynamoDBAttribute : Attribute
  26. {
  27. }
  28. /// <summary>
  29. /// DynamoDB attribute that marks a class.
  30. /// Specifies that this object can be stored in DynamoDB, the name
  31. /// of the target table, and if attribute names must be automatically
  32. /// converted to lowerCamelCase.
  33. ///
  34. /// Need not be declared on subclasses if present on base class.
  35. /// Can be defined on subclasses to specify different target table
  36. /// or specify different attribute casing.
  37. /// </summary>
  38. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited=true, AllowMultiple=false)]
  39. public sealed class DynamoDBTableAttribute : DynamoDBAttribute
  40. {
  41. /// <summary>
  42. /// Gets and sets the TableName property.
  43. /// </summary>
  44. public string TableName { get; set; }
  45. /// <summary>
  46. /// Gets and sets the LowerCamelCaseProperties property.
  47. /// </summary>
  48. public bool LowerCamelCaseProperties { get; set; }
  49. /// <summary>
  50. /// Construct an instance of DynamoDBTableAttribute
  51. /// </summary>
  52. /// <param name="tableName"></param>
  53. public DynamoDBTableAttribute(string tableName)
  54. : this(tableName, false) { }
  55. /// <summary>
  56. /// Construct an instance of DynamoDBTableAttribute
  57. /// </summary>
  58. /// <param name="tableName"></param>
  59. /// <param name="lowerCamelCaseProperties"></param>
  60. public DynamoDBTableAttribute(string tableName, bool lowerCamelCaseProperties)
  61. {
  62. TableName = tableName;
  63. LowerCamelCaseProperties = lowerCamelCaseProperties;
  64. }
  65. }
  66. /// <summary>
  67. /// DynamoDB attribute that directs the specified attribute not to
  68. /// be included when saving or loading objects.
  69. /// </summary>
  70. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
  71. public sealed class DynamoDBIgnoreAttribute : DynamoDBAttribute
  72. {
  73. }
  74. /// <summary>
  75. /// DynamoDB property attribute.
  76. /// Can be used to specify an alternative attribute name or configure
  77. /// a custom converter.
  78. /// </summary>
  79. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
  80. public abstract class DynamoDBRenamableAttribute : DynamoDBAttribute
  81. {
  82. /// <summary>
  83. /// Default constructor
  84. /// </summary>
  85. protected DynamoDBRenamableAttribute()
  86. {
  87. }
  88. /// <summary>
  89. /// Constructor that specifies an alternate attribute name
  90. /// </summary>
  91. /// <param name="attributeName">
  92. /// Name of attribute to be associated with property or field.
  93. /// </param>
  94. protected DynamoDBRenamableAttribute(string attributeName)
  95. {
  96. AttributeName = attributeName;
  97. }
  98. /// <summary>
  99. /// Name of attribute that is associated with this member.
  100. /// </summary>
  101. public string AttributeName { get; set; }
  102. }
  103. /// <summary>
  104. /// DynamoDB property that marks up current member as item version.
  105. /// At most one member in a class may be marked with this attribute.
  106. ///
  107. /// Members that are marked as version must be of primitive,
  108. /// numeric, integer, nullable type (e.g. int?, long?, byte?)
  109. /// </summary>
  110. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
  111. public sealed class DynamoDBVersionAttribute : DynamoDBRenamableAttribute
  112. {
  113. }
  114. /// <summary>
  115. /// DynamoDB property attribute.
  116. /// Can be used to specify an alternative attribute name or configure
  117. /// a custom converter.
  118. /// </summary>
  119. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
  120. public class DynamoDBPropertyAttribute : DynamoDBRenamableAttribute
  121. {
  122. /// <summary>
  123. /// Default constructor
  124. /// </summary>
  125. public DynamoDBPropertyAttribute()
  126. : base()
  127. {
  128. }
  129. /// <summary>
  130. /// Constructor that specifies an alternate attribute name
  131. /// </summary>
  132. /// <param name="attributeName">
  133. /// Name of attribute to be associated with property or field.
  134. /// </param>
  135. public DynamoDBPropertyAttribute(string attributeName)
  136. : base(attributeName)
  137. {
  138. }
  139. /// <summary>
  140. /// Constructor that specifies a custom converter.
  141. ///
  142. /// Converter must be the type of a class that implements IPropertyConverter.
  143. /// </summary>
  144. /// <param name="converter">Custom converter type.</param>
  145. public DynamoDBPropertyAttribute(Type converter)
  146. {
  147. Converter = converter;
  148. }
  149. /// <summary>
  150. /// Constructor that specifies an alternate attribute name and a custom converter.
  151. ///
  152. /// Converter must be the type of a class that implements IPropertyConverter.
  153. /// </summary>
  154. /// <param name="attributeName">
  155. /// Name of attribute to be associated with property or field.
  156. /// </param>
  157. /// <param name="converter">Custom converter type.</param>
  158. public DynamoDBPropertyAttribute(string attributeName, Type converter)
  159. : base(attributeName)
  160. {
  161. Converter = converter;
  162. }
  163. /// <summary>
  164. /// Type of the custom converter.
  165. /// </summary>
  166. public Type Converter { get; set; }
  167. }
  168. /// <summary>
  169. /// DynamoDB property that marks up current member as a hash key element.
  170. /// Exactly one member in a class must be marked with this attribute.
  171. ///
  172. /// Members that are marked as hash key must be convertible to
  173. /// a Primitive object.
  174. /// </summary>
  175. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
  176. public class DynamoDBHashKeyAttribute : DynamoDBPropertyAttribute
  177. {
  178. /// <summary>
  179. /// Default constructor
  180. /// </summary>
  181. public DynamoDBHashKeyAttribute()
  182. : base()
  183. {
  184. }
  185. /// <summary>
  186. /// Constructor that specifies an alternate attribute name
  187. /// </summary>
  188. /// <param name="attributeName">
  189. /// Name of attribute to be associated with property or field.
  190. /// </param>
  191. public DynamoDBHashKeyAttribute(string attributeName)
  192. : base(attributeName)
  193. {
  194. }
  195. /// <summary>
  196. /// Constructor that specifies a custom converter.
  197. ///
  198. /// Converter must be the type of a class that implements IPropertyConverter.
  199. /// </summary>
  200. /// <param name="converter">Custom converter type.</param>
  201. public DynamoDBHashKeyAttribute(Type converter)
  202. : base(converter)
  203. {
  204. }
  205. /// <summary>
  206. /// Constructor that specifies an alternate attribute name and a custom converter.
  207. ///
  208. /// Converter must be the type of a class that implements IPropertyConverter.
  209. /// </summary>
  210. /// <param name="attributeName">
  211. /// Name of attribute to be associated with property or field.
  212. /// </param>
  213. /// <param name="converter">Custom converter type.</param>
  214. public DynamoDBHashKeyAttribute(string attributeName, Type converter)
  215. : base(attributeName, converter)
  216. {
  217. }
  218. }
  219. /// <summary>
  220. /// DynamoDB property that marks up current member as range key element (for a hash-and-range primary key).
  221. /// At most one member in a class may be marked with this attribute.
  222. ///
  223. /// Members that are marked as a range key element must be convertible to
  224. /// a Primitive object.
  225. /// </summary>
  226. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
  227. public class DynamoDBRangeKeyAttribute : DynamoDBPropertyAttribute
  228. {
  229. /// <summary>
  230. /// Default constructor
  231. /// </summary>
  232. public DynamoDBRangeKeyAttribute()
  233. : base()
  234. {
  235. }
  236. /// <summary>
  237. /// Constructor that specifies an alternate attribute name
  238. /// </summary>
  239. /// <param name="attributeName">
  240. /// Name of attribute to be associated with property or field.
  241. /// </param>
  242. public DynamoDBRangeKeyAttribute(string attributeName)
  243. : base(attributeName)
  244. {
  245. }
  246. /// <summary>
  247. /// Constructor that specifies a custom converter.
  248. ///
  249. /// Converter must be the type of a class that implements IPropertyConverter.
  250. /// </summary>
  251. /// <param name="converter">Custom converter type.</param>
  252. public DynamoDBRangeKeyAttribute(Type converter)
  253. : base(converter)
  254. {
  255. }
  256. /// <summary>
  257. /// Constructor that specifies an alternate attribute name and a custom converter.
  258. ///
  259. /// Converter must be the type of a class that implements IPropertyConverter.
  260. /// </summary>
  261. /// <param name="attributeName">
  262. /// Name of attribute to be associated with property or field.
  263. /// </param>
  264. /// <param name="converter">Custom converter type.</param>
  265. public DynamoDBRangeKeyAttribute(string attributeName, Type converter)
  266. : base(attributeName, converter)
  267. {
  268. }
  269. }
  270. /// DynamoDB property attribute that marks up current member as a hash key element for a Global Secondary Index on a table.
  271. ///
  272. /// Members that are marked as a Global Secondary Index hash key element must be convertible to a Primitive object.
  273. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
  274. public class DynamoDBGlobalSecondaryIndexHashKeyAttribute : DynamoDBHashKeyAttribute
  275. {
  276. /// <summary>
  277. /// Index associated with this range key
  278. /// </summary>
  279. public string[] IndexNames { get; set; }
  280. /// <summary>
  281. /// Constructor that accepts a single inde name.
  282. /// </summary>
  283. /// <param name="indexName">Name of the Local Secondary Index this range key belongs to.</param>
  284. public DynamoDBGlobalSecondaryIndexHashKeyAttribute(string indexName)
  285. : base()
  286. {
  287. IndexNames = new string[] { indexName };
  288. }
  289. /// <summary>
  290. /// Constructor that accepts multiple index names.
  291. /// </summary>
  292. /// <param name="indexNames">Names of the Local Secondary Indexes this range key belongs to.</param>
  293. public DynamoDBGlobalSecondaryIndexHashKeyAttribute(params string[] indexNames)
  294. : base()
  295. {
  296. IndexNames = indexNames.Distinct(StringComparer.Ordinal).ToArray();
  297. }
  298. }
  299. /// DynamoDB property attribute that marks up current member as range key element for a Global Secondary Index on a table.
  300. ///
  301. /// Members that are marked as a Global Secondary Index range key element must be convertible to a Primitive object.
  302. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
  303. public class DynamoDBGlobalSecondaryIndexRangeKeyAttribute : DynamoDBRangeKeyAttribute
  304. {
  305. /// <summary>
  306. /// Index associated with this range key
  307. /// </summary>
  308. public string[] IndexNames { get; set; }
  309. /// <summary>
  310. /// Constructor that accepts a single inde name.
  311. /// </summary>
  312. /// <param name="indexName">Name of the Local Secondary Index this range key belongs to.</param>
  313. public DynamoDBGlobalSecondaryIndexRangeKeyAttribute(string indexName)
  314. : base()
  315. {
  316. IndexNames = new string[] { indexName };
  317. }
  318. /// <summary>
  319. /// Constructor that accepts multiple index names.
  320. /// </summary>
  321. /// <param name="indexNames">Names of the Local Secondary Indexes this range key belongs to.</param>
  322. public DynamoDBGlobalSecondaryIndexRangeKeyAttribute(params string[] indexNames)
  323. : base()
  324. {
  325. IndexNames = indexNames.Distinct(StringComparer.Ordinal).ToArray();
  326. }
  327. }
  328. /// <summary>
  329. /// DynamoDB property that marks up current member as range key element for a Local Secondary Index on a table.
  330. ///
  331. /// Members that are marked as a Local Secondary Index range key element must be convertible to a Primitive object.
  332. /// </summary>
  333. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
  334. public sealed class DynamoDBLocalSecondaryIndexRangeKeyAttribute : DynamoDBPropertyAttribute
  335. {
  336. /// <summary>
  337. /// Index associated with this range key
  338. /// </summary>
  339. public string[] IndexNames { get; set; }
  340. /// <summary>
  341. /// Constructor that accepts a single inde name.
  342. /// </summary>
  343. /// <param name="indexName">Name of the Local Secondary Index this range key belongs to.</param>
  344. public DynamoDBLocalSecondaryIndexRangeKeyAttribute(string indexName)
  345. : base()
  346. {
  347. IndexNames = new string[] { indexName };
  348. }
  349. /// <summary>
  350. /// Constructor that accepts multiple index names.
  351. /// </summary>
  352. /// <param name="indexNames">Names of the Local Secondary Indexes this range key belongs to.</param>
  353. public DynamoDBLocalSecondaryIndexRangeKeyAttribute(params string[] indexNames)
  354. : base()
  355. {
  356. IndexNames = indexNames.Distinct(StringComparer.Ordinal).ToArray();
  357. }
  358. }
  359. }