@@ -111,7 +111,7 @@ public LinesBuilder Build(CompositionCode composition)
111111 {
112112 if ( ! marker . IsMarker ( setup , type ) )
113113 {
114- classes . Add ( new Class ( type . ContainingNamespace ? . ToDisplayString ( ) ?? "" , FormatType ( setup , type , DefaultFormatOptions ) , "" , type , new LinesBuilder ( ) ) ) ;
114+ classes . Add ( new Class ( ResolveNamespaceName ( type . ContainingNamespace ) , FormatType ( setup , type , DefaultFormatOptions ) , "" , type , new LinesBuilder ( ) ) ) ;
115115 }
116116 }
117117
@@ -121,7 +121,7 @@ public LinesBuilder Build(CompositionCode composition)
121121 var sourceType = FormatType ( setup , dependency . Source . Type , DefaultFormatOptions ) ;
122122 if ( ! marker . IsMarker ( setup , dependency . Source . Type ) )
123123 {
124- classes . Add ( new Class ( dependency . Source . Type . ContainingNamespace ? . ToDisplayString ( ) ?? "" , sourceType , "" , dependency . Source . Type , new LinesBuilder ( ) ) ) ;
124+ classes . Add ( new Class ( ResolveNamespaceName ( dependency . Source . Type . ContainingNamespace ) , sourceType , "" , dependency . Source . Type , new LinesBuilder ( ) ) ) ;
125125 }
126126
127127 if ( dependency . Target . Root is not null && rootProperties . TryGetValue ( dependency . Injection , out var root ) )
@@ -133,7 +133,7 @@ public LinesBuilder Build(CompositionCode composition)
133133 var targetType = FormatType ( setup , dependency . Target . Type , DefaultFormatOptions ) ;
134134 if ( ! marker . IsMarker ( setup , dependency . Target . Type ) )
135135 {
136- classes . Add ( new Class ( dependency . Target . Type . ContainingNamespace ? . ToDisplayString ( ) ?? "" , targetType , "" , dependency . Target . Type , new LinesBuilder ( ) ) ) ;
136+ classes . Add ( new Class ( ResolveNamespaceName ( dependency . Target . Type . ContainingNamespace ) , targetType , "" , dependency . Target . Type , new LinesBuilder ( ) ) ) ;
137137 }
138138
139139 if ( dependency . Source . Arg is { } arg )
@@ -327,6 +327,11 @@ private string ResolveTypeName(MdSetup setup, ITypeSymbol typeSymbol)
327327 return typeName . StartsWith ( Names . GlobalNamespacePrefix ) ? typeName [ Names . GlobalNamespacePrefix . Length ..] : typeName ;
328328 }
329329
330+ private static string ResolveNamespaceName ( INamespaceSymbol ? namespaceSymbol ) =>
331+ namespaceSymbol == null || namespaceSymbol . IsGlobalNamespace
332+ ? ""
333+ : namespaceSymbol . ToDisplayString ( ) ;
334+
330335 private static string Format ( Accessibility accessibility ) =>
331336 accessibility switch
332337 {
@@ -356,7 +361,7 @@ public override void VisitDependencyNode(in LinesBuilder ctx, DependencyNode nod
356361 {
357362 var lines = new LinesBuilder ( ) ;
358363 var name = builder . FormatType ( setup , node . Type , options ) ;
359- var cls = new Class ( node . Type . ContainingNamespace ? . ToDisplayString ( ) ?? "" , name , "" , node . Type , lines ) ;
364+ var cls = new Class ( ResolveNamespaceName ( node . Type . ContainingNamespace ) , name , "" , node . Type , lines ) ;
360365 if ( ! marker . IsMarker ( setup , node . Type ) )
361366 {
362367 classes . Add ( cls ) ;
0 commit comments