23
23
24
24
namespace Elastic . Clients . Elasticsearch . Aggregations ;
25
25
26
- internal sealed partial class IAggregationRangeConverter : System . Text . Json . Serialization . JsonConverter < Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange >
26
+ internal sealed partial class AggregationRangeConverter : System . Text . Json . Serialization . JsonConverter < Elastic . Clients . Elasticsearch . Aggregations . AggregationRange >
27
27
{
28
- public override Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Read ( ref System . Text . Json . Utf8JsonReader reader , System . Type typeToConvert , System . Text . Json . JsonSerializerOptions options )
29
- {
30
- return reader . ReadValue < Elastic . Clients . Elasticsearch . Aggregations . UntypedAggregationRange > ( options , null ) ;
31
- }
28
+ private static readonly System . Text . Json . JsonEncodedText PropFrom = System . Text . Json . JsonEncodedText . Encode ( "from" ) ;
29
+ private static readonly System . Text . Json . JsonEncodedText PropKey = System . Text . Json . JsonEncodedText . Encode ( "key" ) ;
30
+ private static readonly System . Text . Json . JsonEncodedText PropTo = System . Text . Json . JsonEncodedText . Encode ( "to" ) ;
32
31
33
- public override void Write ( System . Text . Json . Utf8JsonWriter writer , Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange value , System . Text . Json . JsonSerializerOptions options )
32
+ public override Elastic . Clients . Elasticsearch . Aggregations . AggregationRange Read ( ref System . Text . Json . Utf8JsonReader reader , System . Type typeToConvert , System . Text . Json . JsonSerializerOptions options )
34
33
{
35
- switch ( value )
34
+ reader . ValidateToken ( System . Text . Json . JsonTokenType . StartObject ) ;
35
+ LocalJsonValue < double ? > propFrom = default ;
36
+ LocalJsonValue < string ? > propKey = default ;
37
+ LocalJsonValue < double ? > propTo = default ;
38
+ while ( reader . Read ( ) && reader . TokenType is System . Text . Json . JsonTokenType . PropertyName )
36
39
{
37
- case Elastic . Clients . Elasticsearch . Aggregations . DateAggregationRange v :
38
- writer . WriteValue ( options , v , null ) ;
39
- break ;
40
- case Elastic . Clients . Elasticsearch . Aggregations . NumberAggregationRange v :
41
- writer . WriteValue ( options , v , null ) ;
42
- break ;
43
- case Elastic . Clients . Elasticsearch . Aggregations . TermAggregationRange v :
44
- writer . WriteValue ( options , v , null ) ;
45
- break ;
46
- case Elastic . Clients . Elasticsearch . Aggregations . UntypedAggregationRange v :
47
- writer . WriteValue ( options , v , null ) ;
48
- break ;
49
- default :
50
- throw new System . Text . Json . JsonException ( $ "Variant '{ value . Type } ' is not supported for type '{ nameof ( Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange ) } '.") ;
40
+ if ( propFrom . TryReadProperty ( ref reader , options , PropFrom , null ) )
41
+ {
42
+ continue ;
43
+ }
44
+
45
+ if ( propKey . TryReadProperty ( ref reader , options , PropKey , null ) )
46
+ {
47
+ continue ;
48
+ }
49
+
50
+ if ( propTo . TryReadProperty ( ref reader , options , PropTo , null ) )
51
+ {
52
+ continue ;
53
+ }
54
+
55
+ if ( options . UnmappedMemberHandling is System . Text . Json . Serialization . JsonUnmappedMemberHandling . Skip )
56
+ {
57
+ reader . Skip ( ) ;
58
+ continue ;
59
+ }
60
+
61
+ throw new System . Text . Json . JsonException ( $ "Unknown JSON property '{ reader . GetString ( ) } ' for type '{ typeToConvert . Name } '.") ;
51
62
}
52
- }
53
- }
54
-
55
- [ System . Text . Json . Serialization . JsonConverter ( typeof ( Elastic . Clients . Elasticsearch . Aggregations . IAggregationRangeConverter ) ) ]
56
- public partial interface IAggregationRange
57
- {
58
- public string Type { get ; }
59
- }
60
63
61
- public readonly partial struct IAggregationRangeFactory
62
- {
63
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Date ( Elastic . Clients . Elasticsearch . Aggregations . DateAggregationRange value )
64
- {
65
- return value ;
64
+ reader . ValidateToken ( System . Text . Json . JsonTokenType . EndObject ) ;
65
+ return new Elastic . Clients . Elasticsearch . Aggregations . AggregationRange ( Elastic . Clients . Elasticsearch . Serialization . JsonConstructorSentinel . Instance )
66
+ {
67
+ From = propFrom . Value ,
68
+ Key = propKey . Value ,
69
+ To = propTo . Value
70
+ } ;
66
71
}
67
72
68
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Date ( )
73
+ public override void Write ( System . Text . Json . Utf8JsonWriter writer , Elastic . Clients . Elasticsearch . Aggregations . AggregationRange value , System . Text . Json . JsonSerializerOptions options )
69
74
{
70
- return Elastic . Clients . Elasticsearch . Aggregations . DateAggregationRangeDescriptor . Build ( null ) ;
75
+ writer . WriteStartObject ( ) ;
76
+ writer . WriteProperty ( options , PropFrom , value . From , null , null ) ;
77
+ writer . WriteProperty ( options , PropKey , value . Key , null , null ) ;
78
+ writer . WriteProperty ( options , PropTo , value . To , null , null ) ;
79
+ writer . WriteEndObject ( ) ;
71
80
}
81
+ }
72
82
73
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Date ( System . Action < Elastic . Clients . Elasticsearch . Aggregations . DateAggregationRangeDescriptor > ? action )
83
+ [ System . Text . Json . Serialization . JsonConverter ( typeof ( Elastic . Clients . Elasticsearch . Aggregations . AggregationRangeConverter ) ) ]
84
+ public sealed partial class AggregationRange
85
+ {
86
+ #if NET7_0_OR_GREATER
87
+ public AggregationRange ( )
74
88
{
75
- return Elastic . Clients . Elasticsearch . Aggregations . DateAggregationRangeDescriptor . Build ( action ) ;
76
89
}
77
-
78
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Number ( Elastic . Clients . Elasticsearch . Aggregations . NumberAggregationRange value )
90
+ #endif
91
+ #if ! NET7_0_OR_GREATER
92
+ public AggregationRange ( )
79
93
{
80
- return value ;
81
94
}
82
-
83
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Number ( )
95
+ #endif
96
+ [ System . Diagnostics . CodeAnalysis . SetsRequiredMembers ]
97
+ internal AggregationRange ( Elastic . Clients . Elasticsearch . Serialization . JsonConstructorSentinel sentinel )
84
98
{
85
- return Elastic . Clients . Elasticsearch . Aggregations . NumberAggregationRangeDescriptor . Build ( null ) ;
99
+ _ = sentinel ;
86
100
}
87
101
88
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Number ( System . Action < Elastic . Clients . Elasticsearch . Aggregations . NumberAggregationRangeDescriptor > ? action )
89
- {
90
- return Elastic . Clients . Elasticsearch . Aggregations . NumberAggregationRangeDescriptor . Build ( action ) ;
91
- }
102
+ /// <summary>
103
+ /// <para>
104
+ /// Start of the range (inclusive).
105
+ /// </para>
106
+ /// </summary>
107
+ public double ? From { get ; set ; }
108
+
109
+ /// <summary>
110
+ /// <para>
111
+ /// Custom key to return the range with.
112
+ /// </para>
113
+ /// </summary>
114
+ public string ? Key { get ; set ; }
115
+
116
+ /// <summary>
117
+ /// <para>
118
+ /// End of the range (exclusive).
119
+ /// </para>
120
+ /// </summary>
121
+ public double ? To { get ; set ; }
122
+ }
92
123
93
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Term ( Elastic . Clients . Elasticsearch . Aggregations . TermAggregationRange value )
94
- {
95
- return value ;
96
- }
124
+ public readonly partial struct AggregationRangeDescriptor
125
+ {
126
+ internal Elastic . Clients . Elasticsearch . Aggregations . AggregationRange Instance { get ; init ; }
97
127
98
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Term ( )
128
+ [ System . Diagnostics . CodeAnalysis . SetsRequiredMembers ]
129
+ public AggregationRangeDescriptor ( Elastic . Clients . Elasticsearch . Aggregations . AggregationRange instance )
99
130
{
100
- return Elastic . Clients . Elasticsearch . Aggregations . TermAggregationRangeDescriptor . Build ( null ) ;
131
+ Instance = instance ;
101
132
}
102
133
103
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Term ( System . Action < Elastic . Clients . Elasticsearch . Aggregations . TermAggregationRangeDescriptor > ? action )
134
+ [ System . Diagnostics . CodeAnalysis . SetsRequiredMembers ]
135
+ public AggregationRangeDescriptor ( )
104
136
{
105
- return Elastic . Clients . Elasticsearch . Aggregations . TermAggregationRangeDescriptor . Build ( action ) ;
137
+ Instance = new Elastic . Clients . Elasticsearch . Aggregations . AggregationRange ( Elastic . Clients . Elasticsearch . Serialization . JsonConstructorSentinel . Instance ) ;
106
138
}
107
139
108
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Untyped ( Elastic . Clients . Elasticsearch . Aggregations . UntypedAggregationRange value )
140
+ public static explicit operator Elastic . Clients . Elasticsearch . Aggregations . AggregationRangeDescriptor ( Elastic . Clients . Elasticsearch . Aggregations . AggregationRange instance ) => new Elastic . Clients . Elasticsearch . Aggregations . AggregationRangeDescriptor ( instance ) ;
141
+ public static implicit operator Elastic . Clients . Elasticsearch . Aggregations . AggregationRange ( Elastic . Clients . Elasticsearch . Aggregations . AggregationRangeDescriptor descriptor ) => descriptor . Instance ;
142
+
143
+ /// <summary>
144
+ /// <para>
145
+ /// Start of the range (inclusive).
146
+ /// </para>
147
+ /// </summary>
148
+ public Elastic . Clients . Elasticsearch . Aggregations . AggregationRangeDescriptor From ( double ? value )
109
149
{
110
- return value ;
150
+ Instance . From = value ;
151
+ return this ;
111
152
}
112
153
113
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Untyped ( )
154
+ /// <summary>
155
+ /// <para>
156
+ /// Custom key to return the range with.
157
+ /// </para>
158
+ /// </summary>
159
+ public Elastic . Clients . Elasticsearch . Aggregations . AggregationRangeDescriptor Key ( string ? value )
114
160
{
115
- return Elastic . Clients . Elasticsearch . Aggregations . UntypedAggregationRangeDescriptor . Build ( null ) ;
161
+ Instance . Key = value ;
162
+ return this ;
116
163
}
117
164
118
- public Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Untyped ( System . Action < Elastic . Clients . Elasticsearch . Aggregations . UntypedAggregationRangeDescriptor > ? action )
165
+ /// <summary>
166
+ /// <para>
167
+ /// End of the range (exclusive).
168
+ /// </para>
169
+ /// </summary>
170
+ public Elastic . Clients . Elasticsearch . Aggregations . AggregationRangeDescriptor To ( double ? value )
119
171
{
120
- return Elastic . Clients . Elasticsearch . Aggregations . UntypedAggregationRangeDescriptor . Build ( action ) ;
172
+ Instance . To = value ;
173
+ return this ;
121
174
}
122
175
123
176
[ System . Runtime . CompilerServices . MethodImpl ( System . Runtime . CompilerServices . MethodImplOptions . AggressiveInlining ) ]
124
- internal static Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange Build ( System . Func < Elastic . Clients . Elasticsearch . Aggregations . IAggregationRangeFactory , Elastic . Clients . Elasticsearch . Aggregations . IAggregationRange > action )
177
+ internal static Elastic . Clients . Elasticsearch . Aggregations . AggregationRange Build ( System . Action < Elastic . Clients . Elasticsearch . Aggregations . AggregationRangeDescriptor > ? action )
125
178
{
126
- var builder = new Elastic . Clients . Elasticsearch . Aggregations . IAggregationRangeFactory ( ) ;
127
- return action . Invoke ( builder ) ;
179
+ if ( action is null )
180
+ {
181
+ return new Elastic . Clients . Elasticsearch . Aggregations . AggregationRange ( Elastic . Clients . Elasticsearch . Serialization . JsonConstructorSentinel . Instance ) ;
182
+ }
183
+
184
+ var builder = new Elastic . Clients . Elasticsearch . Aggregations . AggregationRangeDescriptor ( new Elastic . Clients . Elasticsearch . Aggregations . AggregationRange ( Elastic . Clients . Elasticsearch . Serialization . JsonConstructorSentinel . Instance ) ) ;
185
+ action . Invoke ( builder ) ;
186
+ return builder . Instance ;
128
187
}
129
188
}
0 commit comments