@@ -79,7 +79,7 @@ internal abstract class SourceTypeBuilderBase : SourceTypeBuilder
7979 {
8080 return null ;
8181 }
82- return FindNamespaceFromViewImports ( Path . GetDirectoryName ( startDir ) , projectDir , importFileName , importFileExtension , out typeRoot ) ;
82+ return FindNamespaceFromViewImports ( Path . GetDirectoryName ( startDir ) ?? "" , projectDir , importFileName , importFileExtension , out typeRoot ) ;
8383
8484 }
8585 /*
@@ -89,28 +89,30 @@ protected string DetermineNamespaceFromPath(string path, string? rootNamespace,
8989 {
9090 var relativePath = Path . GetRelativePath ( projectDir , path ) ;
9191 relativePath = Path . GetDirectoryName ( relativePath ) ;
92- if ( relativePath . StartsWith ( Path . DirectorySeparatorChar ) )
92+ if ( relativePath != null )
9393 {
94- relativePath = relativePath . Substring ( 1 ) ;
95- }
96- if ( relativePath . EndsWith ( Path . DirectorySeparatorChar ) )
97- {
98- relativePath = relativePath [ ..^ 1 ] ;
99- }
100- relativePath = relativePath . Replace ( Path . DirectorySeparatorChar , '.' ) ;
101- if ( rootNamespace != null && rootNamespace . Length != 0 )
102- {
103- if ( relativePath . Length > 0 )
94+ if ( relativePath . StartsWith ( Path . DirectorySeparatorChar ) )
10495 {
105- return rootNamespace + "." + relativePath ;
96+ relativePath = relativePath . Substring ( 1 ) ;
10697 }
107- else
98+ if ( relativePath . EndsWith ( Path . DirectorySeparatorChar ) )
10899 {
109- return rootNamespace ;
100+ relativePath = relativePath [ ..^ 1 ] ;
101+ }
102+ relativePath = relativePath . Replace ( Path . DirectorySeparatorChar , '.' ) ;
103+ if ( rootNamespace != null && rootNamespace . Length != 0 )
104+ {
105+ if ( relativePath . Length > 0 )
106+ {
107+ return rootNamespace + "." + relativePath ;
108+ }
109+ else
110+ {
111+ return rootNamespace ;
112+ }
110113 }
111114 }
112-
113- return relativePath ;
115+ return relativePath ?? "" ;
114116 }
115117 }
116118
@@ -124,7 +126,7 @@ public override SourceType Build(string? rootNamespace, string filePath, string
124126 var ns = ReadNamespaceFromFile ( filePath ) ;
125127 if ( ns == null )
126128 {
127- ns = FindNamespaceFromViewImports ( Path . GetDirectoryName ( filePath ) , projectDir , "_Imports" , ".razor" , out string ? typeRoot ) ;
129+ ns = FindNamespaceFromViewImports ( Path . GetDirectoryName ( filePath ) ?? "" , projectDir , "_Imports" , ".razor" , out string ? typeRoot ) ;
128130 ns = DetermineNamespaceFromPath ( filePath , ns ?? rootNamespace , typeRoot ?? projectDir ) ;
129131 }
130132 ns ??= "" ;
@@ -145,7 +147,7 @@ public override SourceType Build(string? rootNamespace, string filePath, string
145147 var ns = ReadNamespaceFromFile ( filePath ) ;
146148 if ( ns == null )
147149 {
148- ns = FindNamespaceFromViewImports ( Path . GetDirectoryName ( filePath ) , projectDir , "_ViewImports" , Path . GetExtension ( filePath ) , out string ? typeRoot ) ;
150+ ns = FindNamespaceFromViewImports ( Path . GetDirectoryName ( filePath ) ?? "" , projectDir , "_ViewImports" , Path . GetExtension ( filePath ) , out string ? typeRoot ) ;
149151 ns = DetermineNamespaceFromPath ( filePath , ns ?? rootNamespace , typeRoot ?? projectDir ) ;
150152 }
151153 ns ??= "" ;
@@ -160,15 +162,19 @@ private string GetTypeName(string filePath, string projectDir)
160162 {
161163 var relativeFile = Path . GetRelativePath ( projectDir , filePath ) ;
162164 var relativeDir = Path . GetDirectoryName ( relativeFile ) ;
163- if ( relativeDir . StartsWith ( Path . DirectorySeparatorChar ) )
164- {
165- relativeDir = relativeDir . Substring ( 1 ) ;
166- }
167- if ( relativeDir . EndsWith ( Path . DirectorySeparatorChar ) )
165+ if ( relativeDir != null )
168166 {
169- relativeDir = relativeDir [ ..^ 1 ] ;
167+ if ( relativeDir . StartsWith ( Path . DirectorySeparatorChar ) )
168+ {
169+ relativeDir = relativeDir . Substring ( 1 ) ;
170+ }
171+ if ( relativeDir . EndsWith ( Path . DirectorySeparatorChar ) )
172+ {
173+ relativeDir = relativeDir [ ..^ 1 ] ;
174+ }
175+ return relativeDir . Replace ( Path . DirectorySeparatorChar , '_' ) + "_" + Path . GetFileNameWithoutExtension ( filePath ) ;
170176 }
171- return relativeDir . Replace ( Path . DirectorySeparatorChar , '_' ) + "_" + Path . GetFileNameWithoutExtension ( filePath ) ;
177+ return "" ;
172178 }
173179 }
174180 internal class SourceTypeBuilderFactory
0 commit comments