File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed
Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -4,19 +4,27 @@ namespace System.Management.Generator;
44public class CodeGenerator
55{
66 private static readonly HashSet < string > _excludedFolders = new ( StringComparer . OrdinalIgnoreCase ) { "bin" , "obj" } ;
7- public const string DefaultTargetDirectory = "..\\ ..\\ ..\\ ..\\ Types\\ " ;
7+
8+ private static DirectoryInfo FindTypesDirectory ( )
9+ {
10+ var dir = new DirectoryInfo ( Environment . CurrentDirectory ) ;
11+ while ( dir != null )
12+ {
13+ var typesDir = new DirectoryInfo ( Path . Combine ( dir . FullName , "Types" ) ) ;
14+ if ( typesDir . Exists )
15+ return typesDir ;
16+ dir = dir . Parent ;
17+ }
18+ throw new DirectoryNotFoundException ( "Could not find 'Types' directory in any parent directory." ) ;
19+ }
20+
821 private readonly Dictionary < string , ClassDefinition > _classDefinitions ;
922 private readonly DirectoryInfo _targetDirectory ;
1023
11- public CodeGenerator ( IEnumerable < ClassDefinition > classDefinitions , string targetDirectory = DefaultTargetDirectory )
24+ public CodeGenerator ( IEnumerable < ClassDefinition > classDefinitions )
1225 {
1326 _classDefinitions = classDefinitions . ToDictionary ( t => t . ClassName , t => t , StringComparer . InvariantCultureIgnoreCase ) ;
14- _targetDirectory = new DirectoryInfo ( targetDirectory ) ;
15-
16- if ( ! _targetDirectory . Exists )
17- {
18- _targetDirectory . Create ( ) ;
19- }
27+ _targetDirectory = FindTypesDirectory ( ) ;
2028 }
2129
2230 public void GenerateCode ( )
You can’t perform that action at this time.
0 commit comments