-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSharpCodeBuilder.AppendFormat.cs
More file actions
112 lines (102 loc) · 7.02 KB
/
CSharpCodeBuilder.AppendFormat.cs
File metadata and controls
112 lines (102 loc) · 7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
namespace NetEvolve.CodeBuilder;
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
public partial class CSharpCodeBuilder
{
/// <summary>
/// Appends a formatted string to the current builder using invariant culture.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg0">The object to format.</param>
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="format"/> is <see langword="null"/>.</exception>
/// <exception cref="FormatException">Thrown when <paramref name="format"/> is invalid or the index of a format item is greater than zero.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CSharpCodeBuilder AppendFormat(string format, object? arg0) =>
AppendFormat(CultureInfo.InvariantCulture, format, arg0);
/// <summary>
/// Appends a formatted string to the current builder using invariant culture.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="args">An array of objects to format.</param>
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="format"/> is <see langword="null"/>.</exception>
/// <exception cref="FormatException">Thrown when <paramref name="format"/> is invalid or the index of a format item is greater than the number of elements in <paramref name="args"/> minus 1.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CSharpCodeBuilder AppendFormat(string format, params object?[] args) =>
AppendFormat(CultureInfo.InvariantCulture, format, args);
/// <summary>
/// Appends a formatted string to the current builder using the specified format provider.
/// </summary>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="format">A composite format string.</param>
/// <param name="args">An array of objects to format.</param>
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="format"/> is <see langword="null"/>.</exception>
/// <exception cref="FormatException">Thrown when <paramref name="format"/> is invalid or the index of a format item is greater than the number of elements in <paramref name="args"/> minus 1.</exception>
public CSharpCodeBuilder AppendFormat(IFormatProvider? provider, string format, params object?[] args)
{
EnsureIndented();
_ = _builder.AppendFormat(provider, format, args);
return this;
}
/// <summary>
/// Appends a formattable string to the current builder using invariant culture.
/// </summary>
/// <param name="formattable">The formattable string to append.</param>
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <remarks>If <paramref name="formattable"/> is <see langword="null"/>, the method returns without appending anything.</remarks>
public CSharpCodeBuilder AppendFormat(FormattableString? formattable)
{
if (formattable is null)
{
return this;
}
EnsureIndented();
_ = _builder.Append(formattable.ToString(CultureInfo.InvariantCulture));
return this;
}
/// <summary>
/// Appends a formatted string followed by a line terminator to the current builder using invariant culture.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg0">The object to format.</param>
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="format"/> is <see langword="null"/>.</exception>
/// <exception cref="FormatException">Thrown when <paramref name="format"/> is invalid or the index of a format item is greater than zero.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CSharpCodeBuilder AppendLineFormat(string format, object? arg0) =>
AppendFormat(CultureInfo.InvariantCulture, format, arg0).AppendLine();
/// <summary>
/// Appends a formatted string followed by a line terminator to the current builder using invariant culture.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="args">An array of objects to format.</param>
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="format"/> is <see langword="null"/>.</exception>
/// <exception cref="FormatException">Thrown when <paramref name="format"/> is invalid or the index of a format item is greater than the number of elements in <paramref name="args"/> minus 1.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CSharpCodeBuilder AppendLineFormat(string format, params object?[] args) =>
AppendFormat(CultureInfo.InvariantCulture, format, args).AppendLine();
/// <summary>
/// Appends a formatted string followed by a line terminator to the current builder using the specified format provider.
/// </summary>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="format">A composite format string.</param>
/// <param name="args">An array of objects to format.</param>
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="format"/> is <see langword="null"/>.</exception>
/// <exception cref="FormatException">Thrown when <paramref name="format"/> is invalid or the index of a format item is greater than the number of elements in <paramref name="args"/> minus 1.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CSharpCodeBuilder AppendLineFormat(IFormatProvider? provider, string format, params object?[] args) =>
AppendFormat(provider, format, args).AppendLine();
/// <summary>
/// Appends a formattable string followed by a line terminator to the current builder using invariant culture.
/// </summary>
/// <param name="formattable">The formattable string to append.</param>
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <remarks>If <paramref name="formattable"/> is <see langword="null"/>, only the line terminator is appended.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CSharpCodeBuilder AppendLineFormat(FormattableString? formattable) => AppendFormat(formattable).AppendLine();
}