openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
mailinhphan/clientOptions

Branches

Tags

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

Clone

HTTPS

Download ZIP

OpenAI/src/Generated/Internal/Argument.cs

94lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.Collections;
7using System.Collections.Generic;
8
9namespace OpenAI
10{
11 internal static partial class Argument
12 {
13 public static void AssertNotNull<T>(T value, string name)
14 {
15 if (value is null)
16 {
17 throw new ArgumentNullException(name);
18 }
19 }
20
21 public static void AssertNotNull<T>(T? value, string name)
22 where T : struct
23 {
24 if (!value.HasValue)
25 {
26 throw new ArgumentNullException(name);
27 }
28 }
29
30 public static void AssertNotNullOrEmpty<T>(IEnumerable<T> value, string name)
31 {
32 if (value is null)
33 {
34 throw new ArgumentNullException(name);
35 }
36 if (value is ICollection<T> collectionOfT && collectionOfT.Count == 0)
37 {
38 throw new ArgumentException("Value cannot be an empty collection.", name);
39 }
40 if (value is ICollection collection && collection.Count == 0)
41 {
42 throw new ArgumentException("Value cannot be an empty collection.", name);
43 }
44 using IEnumerator<T> e = value.GetEnumerator();
45 if (!e.MoveNext())
46 {
47 throw new ArgumentException("Value cannot be an empty collection.", name);
48 }
49 }
50
51 public static void AssertNotNullOrEmpty(string value, string name)
52 {
53 if (value is null)
54 {
55 throw new ArgumentNullException(name);
56 }
57 if (value.Length == 0)
58 {
59 throw new ArgumentException("Value cannot be an empty string.", name);
60 }
61 }
62
63 public static void AssertNotNullOrWhiteSpace(string value, string name)
64 {
65 if (value is null)
66 {
67 throw new ArgumentNullException(name);
68 }
69 if (string.IsNullOrWhiteSpace(value))
70 {
71 throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name);
72 }
73 }
74
75 public static void AssertInRange<T>(T value, T minimum, T maximum, string name)
76 where T : notnull, IComparable<T>
77 {
78 if (minimum.CompareTo(value) > 0)
79 {
80 throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed.");
81 }
82 if (maximum.CompareTo(value) < 0)
83 {
84 throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed.");
85 }
86 }
87
88 public static string CheckNotNullOrEmpty(string value, string name)
89 {
90 AssertNotNullOrEmpty(value, name);
91 return value;
92 }
93 }
94}
95