@@ -99,6 +99,11 @@ public static IHtmlContentBuilder AppendFormat(
99
99
/// <returns>The <see cref="IHtmlContentBuilder"/>.</returns>
100
100
public static IHtmlContentBuilder AppendLine ( this IHtmlContentBuilder builder )
101
101
{
102
+ if ( builder == null )
103
+ {
104
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
105
+ }
106
+
102
107
builder . Append ( HtmlEncodedString . NewLine ) ;
103
108
return builder ;
104
109
}
@@ -112,6 +117,11 @@ public static IHtmlContentBuilder AppendLine(this IHtmlContentBuilder builder)
112
117
/// <returns>The <see cref="IHtmlContentBuilder"/>.</returns>
113
118
public static IHtmlContentBuilder AppendLine ( this IHtmlContentBuilder builder , string unencoded )
114
119
{
120
+ if ( builder == null )
121
+ {
122
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
123
+ }
124
+
115
125
builder . Append ( unencoded ) ;
116
126
builder . Append ( HtmlEncodedString . NewLine ) ;
117
127
return builder ;
@@ -125,6 +135,11 @@ public static IHtmlContentBuilder AppendLine(this IHtmlContentBuilder builder, s
125
135
/// <returns>The <see cref="IHtmlContentBuilder"/>.</returns>
126
136
public static IHtmlContentBuilder AppendLine ( this IHtmlContentBuilder builder , IHtmlContent content )
127
137
{
138
+ if ( builder == null )
139
+ {
140
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
141
+ }
142
+
128
143
builder . Append ( content ) ;
129
144
builder . Append ( HtmlEncodedString . NewLine ) ;
130
145
return builder ;
@@ -139,6 +154,11 @@ public static IHtmlContentBuilder AppendLine(this IHtmlContentBuilder builder, I
139
154
/// <returns>The <see cref="IHtmlContentBuilder"/>.</returns>
140
155
public static IHtmlContentBuilder AppendHtmlLine ( this IHtmlContentBuilder builder , string encoded )
141
156
{
157
+ if ( builder == null )
158
+ {
159
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
160
+ }
161
+
142
162
builder . AppendHtml ( encoded ) ;
143
163
builder . Append ( HtmlEncodedString . NewLine ) ;
144
164
return builder ;
@@ -153,6 +173,11 @@ public static IHtmlContentBuilder AppendHtmlLine(this IHtmlContentBuilder builde
153
173
/// <returns>The <see cref="IHtmlContentBuilder"/>.</returns>
154
174
public static IHtmlContentBuilder SetContent ( this IHtmlContentBuilder builder , string unencoded )
155
175
{
176
+ if ( builder == null )
177
+ {
178
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
179
+ }
180
+
156
181
builder . Clear ( ) ;
157
182
builder . Append ( unencoded ) ;
158
183
return builder ;
@@ -166,6 +191,11 @@ public static IHtmlContentBuilder SetContent(this IHtmlContentBuilder builder, s
166
191
/// <returns>The <see cref="IHtmlContentBuilder"/>.</returns>
167
192
public static IHtmlContentBuilder SetContent ( this IHtmlContentBuilder builder , IHtmlContent content )
168
193
{
194
+ if ( builder == null )
195
+ {
196
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
197
+ }
198
+
169
199
builder . Clear ( ) ;
170
200
builder . Append ( content ) ;
171
201
return builder ;
@@ -180,6 +210,11 @@ public static IHtmlContentBuilder SetContent(this IHtmlContentBuilder builder, I
180
210
/// <returns>The <see cref="IHtmlContentBuilder"/>.</returns>
181
211
public static IHtmlContentBuilder SetHtmlContent ( this IHtmlContentBuilder builder , string encoded )
182
212
{
213
+ if ( builder == null )
214
+ {
215
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
216
+ }
217
+
183
218
builder . Clear ( ) ;
184
219
builder . AppendHtml ( encoded ) ;
185
220
return builder ;
@@ -256,8 +291,14 @@ public EncodingFormatProvider(IFormatProvider formatProvider, HtmlEncoder encode
256
291
257
292
public string Format ( string format , object arg , IFormatProvider formatProvider )
258
293
{
259
- // This is the case we need to special case. We trust the IHtmlContent instance to do the
260
- // right thing with encoding.
294
+ // These are the cases we need to special case. We trust the HtmlEncodedString or IHtmlContent instance
295
+ // to do the right thing with encoding.
296
+ var htmlString = arg as HtmlEncodedString ;
297
+ if ( htmlString != null )
298
+ {
299
+ return htmlString . ToString ( ) ;
300
+ }
301
+
261
302
var htmlContent = arg as IHtmlContent ;
262
303
if ( htmlContent != null )
263
304
{
0 commit comments