@@ -247,7 +247,8 @@ public ComponentDirectiveVisitor(string filePath, IReadOnlyList<TagHelperDescrip
247
247
{
248
248
// If this is a child content tag helper, we want to add it if it's original type is in scope.
249
249
// E.g, if the type name is `Test.MyComponent.ChildContent`, we want to add it if `Test.MyComponent` is in scope.
250
- TrySplitNamespaceAndType ( typeName , out typeName , out var _ ) ;
250
+ TrySplitNamespaceAndType ( typeName , out var typeNameTextSpan , out var _ ) ;
251
+ typeName = GetTextSpanContent ( typeNameTextSpan , typeName ) ;
251
252
}
252
253
253
254
if ( currentNamespace != null && IsTypeInScope ( typeName , currentNamespace ) )
@@ -336,7 +337,8 @@ public override void VisitRazorDirective(RazorDirectiveSyntax node)
336
337
{
337
338
// If this is a child content tag helper, we want to add it if it's original type is in scope of the given namespace.
338
339
// E.g, if the type name is `Test.MyComponent.ChildContent`, we want to add it if `Test.MyComponent` is in this namespace.
339
- TrySplitNamespaceAndType ( typeName , out typeName , out var _ ) ;
340
+ TrySplitNamespaceAndType ( typeName , out var typeNameTextSpan , out var _ ) ;
341
+ typeName = GetTextSpanContent ( typeNameTextSpan , typeName ) ;
340
342
}
341
343
if ( typeName != null && IsTypeInNamespace ( typeName , @namespace ) )
342
344
{
@@ -350,13 +352,13 @@ public override void VisitRazorDirective(RazorDirectiveSyntax node)
350
352
351
353
internal static bool IsTypeInNamespace ( string typeName , string @namespace )
352
354
{
353
- if ( ! TrySplitNamespaceAndType ( typeName , out var typeNamespace , out var _ ) || typeNamespace == string . Empty )
355
+ if ( ! TrySplitNamespaceAndType ( typeName , out var typeNamespace , out var _ ) || typeNamespace . Length == 0 )
354
356
{
355
357
// Either the typeName is not the full type name or this type is at the top level.
356
358
return true ;
357
359
}
358
360
359
- return typeNamespace . Equals ( @namespace , StringComparison . Ordinal ) ;
361
+ return @namespace . Length == typeNamespace . Length && 0 == string . CompareOrdinal ( typeName , typeNamespace . Start , @namespace , 0 , @namespace . Length ) ;
360
362
}
361
363
362
364
// Check if the given type is already in scope given the namespace of the current document.
@@ -366,12 +368,13 @@ internal static bool IsTypeInNamespace(string typeName, string @namespace)
366
368
// Whereas `MyComponents.SomethingElse.OtherComponent` is not in scope.
367
369
internal static bool IsTypeInScope ( string typeName , string currentNamespace )
368
370
{
369
- if ( ! TrySplitNamespaceAndType ( typeName , out var typeNamespace , out var _ ) || typeNamespace == string . Empty )
371
+ if ( ! TrySplitNamespaceAndType ( typeName , out var typeNamespaceTextSpan , out var _ ) || typeNamespaceTextSpan . Length == 0 )
370
372
{
371
373
// Either the typeName is not the full type name or this type is at the top level.
372
374
return true ;
373
375
}
374
376
377
+ var typeNamespace = GetTextSpanContent ( typeNamespaceTextSpan , typeName ) ;
375
378
var typeNamespaceSegments = typeNamespace . Split ( NamespaceSeparators , StringSplitOptions . RemoveEmptyEntries ) ;
376
379
var currentNamespaceSegments = currentNamespace . Split ( NamespaceSeparators , StringSplitOptions . RemoveEmptyEntries ) ;
377
380
if ( typeNamespaceSegments . Length > currentNamespaceSegments . Length )
@@ -399,21 +402,23 @@ internal static bool IsTagHelperFromMangledClass(TagHelperDescriptor tagHelper)
399
402
{
400
403
// If this is a child content tag helper, we want to look at it's original type.
401
404
// E.g, if the type name is `Test.__generated__MyComponent.ChildContent`, we want to look at `Test.__generated__MyComponent`.
402
- TrySplitNamespaceAndType ( typeName , out typeName , out var _ ) ;
405
+ TrySplitNamespaceAndType ( typeName , out var typeNameTextSpan , out var _ ) ;
406
+ typeName = GetTextSpanContent ( typeNameTextSpan , typeName ) ;
403
407
}
404
- if ( ! TrySplitNamespaceAndType ( typeName , out var _ , out var className ) )
408
+ if ( ! TrySplitNamespaceAndType ( typeName , out var _ , out var classNameTextSpan ) )
405
409
{
406
410
return false ;
407
411
}
412
+ var className = GetTextSpanContent ( classNameTextSpan , typeName ) ;
408
413
409
414
return ComponentMetadata . IsMangledClass ( className ) ;
410
415
}
411
416
412
417
// Internal for testing.
413
- internal static bool TrySplitNamespaceAndType ( string fullTypeName , out string @namespace , out string typeName )
418
+ internal static bool TrySplitNamespaceAndType ( string fullTypeName , out TextSpan @namespace , out TextSpan typeName )
414
419
{
415
- @namespace = string . Empty ;
416
- typeName = string . Empty ;
420
+ @namespace = default ;
421
+ typeName = default ;
417
422
418
423
if ( string . IsNullOrEmpty ( fullTypeName ) )
419
424
{
@@ -442,20 +447,26 @@ internal static bool TrySplitNamespaceAndType(string fullTypeName, out string @n
442
447
443
448
if ( splitLocation == - 1 )
444
449
{
445
- typeName = fullTypeName ;
450
+ typeName = new TextSpan ( 0 , fullTypeName . Length ) ;
446
451
return true ;
447
452
}
448
453
449
- @namespace = fullTypeName . Substring ( 0 , splitLocation ) ;
454
+ @namespace = new TextSpan ( 0 , splitLocation ) ;
450
455
451
456
var typeNameStartLocation = splitLocation + 1 ;
452
457
if ( typeNameStartLocation < fullTypeName . Length )
453
458
{
454
- typeName = fullTypeName . Substring ( typeNameStartLocation , fullTypeName . Length - typeNameStartLocation ) ;
459
+ typeName = new TextSpan ( typeNameStartLocation , fullTypeName . Length - typeNameStartLocation ) ;
455
460
}
456
461
457
462
return true ;
458
463
}
464
+
465
+ // Internal for testing.
466
+ internal static string GetTextSpanContent ( TextSpan textSpan , string s )
467
+ {
468
+ return s . Substring ( textSpan . Start , textSpan . Length ) ;
469
+ }
459
470
}
460
471
}
461
472
}
0 commit comments