@@ -221,8 +221,7 @@ private void WriteToCore(object entry, TextWriter writer, HtmlEncoder encoder)
221
221
return ;
222
222
}
223
223
224
- var stringValue = entry as string ;
225
- if ( stringValue != null )
224
+ if ( entry is string stringValue )
226
225
{
227
226
encoder . Encode ( writer , stringValue ) ;
228
227
}
@@ -239,13 +238,11 @@ private void CopyToCore(object entry, IHtmlContentBuilder destination)
239
238
return ;
240
239
}
241
240
242
- string entryAsString ;
243
- IHtmlContentContainer entryAsContainer ;
244
- if ( ( entryAsString = entry as string ) != null )
241
+ if ( entry is string entryAsString )
245
242
{
246
243
destination . Append ( entryAsString ) ;
247
244
}
248
- else if ( ( entryAsContainer = entry as IHtmlContentContainer ) != null )
245
+ else if ( entry is IHtmlContentContainer entryAsContainer )
249
246
{
250
247
entryAsContainer . CopyTo ( destination ) ;
251
248
}
@@ -262,13 +259,11 @@ private void MoveToCore(object entry, IHtmlContentBuilder destination)
262
259
return ;
263
260
}
264
261
265
- string entryAsString ;
266
- IHtmlContentContainer entryAsContainer ;
267
- if ( ( entryAsString = entry as string ) != null )
262
+ if ( entry is string entryAsString )
268
263
{
269
264
destination . Append ( entryAsString ) ;
270
265
}
271
- else if ( ( entryAsContainer = entry as IHtmlContentContainer ) != null )
266
+ else if ( entry is IHtmlContentContainer entryAsContainer )
272
267
{
273
268
entryAsContainer . MoveTo ( destination ) ;
274
269
}
@@ -282,29 +277,19 @@ private bool IsEmptyOrWhiteSpaceCore(object entry, EmptyOrWhiteSpaceWriter write
282
277
{
283
278
if ( entry == null )
284
279
{
285
- return false ;
280
+ return true ;
286
281
}
287
282
288
- var stringValue = entry as string ;
289
- if ( stringValue != null )
283
+ if ( entry is string stringValue )
290
284
{
291
285
// Do not encode the string because encoded value remains whitespace from user's POV.
292
- if ( ! string . IsNullOrWhiteSpace ( stringValue ) )
293
- {
294
- return false ;
295
- }
296
- }
297
- else
298
- {
299
- // Use NullHtmlEncoder to avoid treating encoded whitespace as non-whitespace e.g. "\t" as "	".
300
- ( ( IHtmlContent ) entry ) . WriteTo ( writer , NullHtmlEncoder . Default ) ;
301
- if ( ! writer . IsEmptyOrWhiteSpace )
302
- {
303
- return false ;
304
- }
286
+ return string . IsNullOrWhiteSpace ( stringValue ) ;
305
287
}
306
288
307
- return true ;
289
+ // Use NullHtmlEncoder to avoid treating encoded whitespace as non-whitespace e.g. "\t" as "	".
290
+ ( ( IHtmlContent ) entry ) . WriteTo ( writer , NullHtmlEncoder . Default ) ;
291
+
292
+ return writer . IsEmptyOrWhiteSpace ;
308
293
}
309
294
310
295
private TagHelperContent AppendCore ( object entry )
@@ -329,7 +314,7 @@ private string DebuggerToString()
329
314
{
330
315
return GetContent ( ) ;
331
316
}
332
-
317
+
333
318
// Overrides Write(string) to find if the content written is empty/whitespace.
334
319
private class EmptyOrWhiteSpaceWriter : TextWriter
335
320
{
@@ -360,4 +345,4 @@ public override void Write(string value)
360
345
}
361
346
}
362
347
}
363
- }
348
+ }
0 commit comments