@@ -89,10 +89,14 @@ private string GenerateSource(SerializableSyntaxReceiver syntaxReceiver)
8989 write ( "using System;" , true ) ;
9090 write ( "using System.Collections.Generic;" , true ) ;
9191
92- var namespaceName = syntaxReceiver . YamlStaticContextType ? . ContainingNamespace . ContainingNamespace ;
92+ var namespaceName = syntaxReceiver . YamlStaticContextType ? . GetNamespace ( ) ;
93+ var isGlobalNamespace = string . IsNullOrEmpty ( namespaceName ) ;
9394
94- write ( $ "namespace { syntaxReceiver . YamlStaticContextType ? . GetNamespace ( ) ?? "YamlDotNet.Static" } ", true ) ;
95- write ( "{" , true ) ; indent ( ) ;
95+ if ( ! isGlobalNamespace )
96+ {
97+ write ( $ "namespace { namespaceName } ", true ) ;
98+ write ( "{" , true ) ; indent ( ) ;
99+ }
96100
97101 new StaticContextFile ( write , indent , unindent , _context ) . Write ( syntaxReceiver ) ;
98102 new StaticObjectFactoryFile ( write , indent , unindent , _context ) . Write ( syntaxReceiver ) ;
@@ -101,7 +105,10 @@ private string GenerateSource(SerializableSyntaxReceiver syntaxReceiver)
101105 new StaticTypeInspectorFile ( write , indent , unindent , _context ) . Write ( syntaxReceiver ) ;
102106 new ObjectAccessorFileGenerator ( write , indent , unindent , _context ) . Write ( syntaxReceiver ) ;
103107
104- unindent ( ) ; write ( "}" , true ) ;
108+ if ( ! isGlobalNamespace )
109+ {
110+ unindent ( ) ; write ( "}" , true ) ;
111+ }
105112 }
106113 catch ( Exception exception )
107114 {
0 commit comments