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.

78 lines
2.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace IPA.Config.Stores.Attributes
  7. {
  8. /// <summary>
  9. /// Causes a field or property in an object being wrapped by <see cref="GeneratedExtension.Generated{T}(Config, bool)"/> to be
  10. /// ignored during serialization and deserialization.
  11. /// </summary>
  12. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
  13. public sealed class IgnoreAttribute : Attribute { }
  14. /// <summary>
  15. /// Indicates that a field or property in an object being wrapped by <see cref="GeneratedExtension.Generated{T}(Config, bool)"/>
  16. /// that would otherwise be nullable (i.e. a reference type or a <see cref="Nullable{T}"/> type) should never be null, and the
  17. /// member will be ignored if the deserialized value is <see langword="null"/>.
  18. /// </summary>
  19. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
  20. public sealed class NonNullableAttribute : Attribute { }
  21. /// <summary>
  22. /// Specifies a name for the serialized field or property in an object being wrapped by
  23. /// <see cref="GeneratedExtension.Generated{T}(Config, bool)"/> that is different from the member name itself.
  24. /// </summary>
  25. /// <example>
  26. /// <para>
  27. /// When serializing the following object, we might get the JSON that follows.
  28. /// <code>
  29. /// public class PluginConfig
  30. /// {
  31. /// public virtual bool BooleanField { get; set; } = true;
  32. /// }
  33. /// </code>
  34. /// <code>
  35. /// {
  36. /// "BooleanField": true
  37. /// }
  38. /// </code>
  39. /// </para>
  40. /// <para>
  41. /// However, if we were to add a <see cref="SerializedNameAttribute"/> to that field, we would get the following.
  42. /// <code>
  43. /// public class PluginConfig
  44. /// {
  45. /// [SerializedName("bool")]
  46. /// public virtual bool BooleanField { get; set; } = true;
  47. /// }
  48. /// </code>
  49. /// <code>
  50. /// {
  51. /// "bool": true
  52. /// }
  53. /// </code>
  54. /// </para>
  55. /// </example>
  56. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
  57. public sealed class SerializedNameAttribute : Attribute
  58. {
  59. /// <summary>
  60. /// Gets the name to replace the member name with.
  61. /// </summary>
  62. public string Name { get; private set; }
  63. /// <summary>
  64. /// Creates a new <see cref="SerializedNameAttribute"/> with the given <see cref="Name"/>.
  65. /// </summary>
  66. /// <param name="name">the value to assign to <see cref="Name"/></param>
  67. public SerializedNameAttribute(string name)
  68. {
  69. Name = name;
  70. }
  71. }
  72. }