openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.10

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Utility/Generator/CodeGenSerializationAttribute.cs

53lines · modecode

1#nullable enable
2
3using System;
4
5namespace OpenAI;
6
7[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true, Inherited = true)]
8internal sealed 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&lt;TypeOfTheProperty&gt; 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}