openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Utility/Generator/CodeGenSerializationAttribute.cs
53lines · modeblame
9f9f2936Jose Arriaga Maldonado2 years ago | 1 | #nullable enable |
| 2 | | |
| 3 | using System; | |
| 4 | | |
| 5 | namespace OpenAI; | |
| 6 | | |
| 7 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true, Inherited = true)] | |
| 8 | internal class CodeGenSerializationAttribute : Attribute | |
| 9 | { | |
| 10 | /// <summary> | |
| 11 | /// Gets or sets the property name which these hooks should apply to | |
| 12 | /// </summary> | |
| 13 | public string? PropertyName { get; set; } | |
| 14 | /// <summary> | |
| 15 | /// Gets or sets the serialization path of the property in the JSON | |
| 16 | /// </summary> | |
| 17 | public string[]? SerializationPath { get; } | |
| 18 | /// <summary> | |
| 19 | /// Gets or sets the method name to use when serializing the property value (property name excluded) | |
| 20 | /// The signature of the serialization hook method must be or compatible with when invoking: | |
| 21 | /// private void SerializeHook(Utf8JsonWriter writer); | |
| 22 | /// </summary> | |
| 23 | public string? SerializationValueHook { get; set; } | |
| 24 | /// <summary> | |
| 25 | /// Gets or sets the method name to use when deserializing the property value from the JSON | |
| 26 | /// private static void DeserializationHook(JsonProperty property, ref TypeOfTheProperty propertyValue); // if the property is required | |
| 27 | /// private static void DeserializationHook(JsonProperty property, ref Optional<TypeOfTheProperty> propertyValue); // if the property is optional | |
| 28 | /// </summary> | |
| 29 | public string? DeserializationValueHook { get; set; } | |
| 30 | /// <summary> | |
| 31 | /// Gets or sets the method name to use when serializing the property value (property name excluded) | |
| 32 | /// The signature of the serialization hook method must be or compatible with when invoking: | |
| 33 | /// private void SerializeHook(StringBuilder builder); | |
| 34 | /// </summary> | |
| 35 | public string? BicepSerializationValueHook { get; set; } | |
| 36 | | |
| 37 | public CodeGenSerializationAttribute(string propertyName) | |
| 38 | { | |
| 39 | PropertyName = propertyName; | |
| 40 | } | |
| 41 | | |
| 42 | public CodeGenSerializationAttribute(string propertyName, string serializationName) | |
| 43 | { | |
| 44 | PropertyName = propertyName; | |
| 45 | SerializationPath = new[] { serializationName }; | |
| 46 | } | |
| 47 | | |
| 48 | public CodeGenSerializationAttribute(string propertyName, string[] serializationPath) | |
| 49 | { | |
| 50 | PropertyName = propertyName; | |
| 51 | SerializationPath = serializationPath; | |
| 52 | } | |
| 53 | } |