@@ -22,7 +22,9 @@ static void Main(string[] args)
2222
2323 private static void WriteFile ( string code , string path )
2424 {
25- Directory . CreateDirectory ( Path . GetDirectoryName ( path ) ) ;
25+ var dir = Path . GetDirectoryName ( path ) ;
26+ if ( dir != null )
27+ Directory . CreateDirectory ( dir ) ;
2628 if ( File . Exists ( path ) )
2729 {
2830 var old = File . ReadAllText ( path ) ;
@@ -120,7 +122,15 @@ private static void GenerateModels(ModelOptions opt)
120122 var codeGenConfig = new CodeGenerationConfig ( ) ;
121123 codeGenConfig . Scan ( assembly ) ;
122124
123- foreach ( var type in assembly . GetTypes ( ) )
125+ var types = assembly . GetTypes ( ) . ToHashSet ( ) ;
126+ foreach ( var builder in codeGenConfig . AdaptAttributeBuilders )
127+ {
128+ foreach ( var setting in builder . TypeSettings )
129+ {
130+ types . Add ( setting . Key ) ;
131+ }
132+ }
133+ foreach ( var type in types )
124134 {
125135 var builders = type . GetAdaptAttributeBuilders ( codeGenConfig )
126136 . Where ( it => ! string . IsNullOrEmpty ( it . Attribute . Name ) && it . Attribute . Name != "[name]" )
@@ -261,7 +271,7 @@ private static Type GetPropertyType(MemberInfo member, Type propType, Type attrT
261271 return mockType ;
262272 }
263273
264- private static Type ? GetFromType ( Type type , BaseAdaptAttribute attr , Type [ ] types )
274+ private static Type ? GetFromType ( Type type , BaseAdaptAttribute attr , HashSet < Type > types )
265275 {
266276 if ( ! ( attr is AdaptFromAttribute ) && ! ( attr is AdaptTwoWaysAttribute ) )
267277 return null ;
@@ -270,13 +280,13 @@ private static Type GetPropertyType(MemberInfo member, Type propType, Type attrT
270280 if ( fromType == null && attr . Name != null )
271281 {
272282 var name = attr . Name . Replace ( "[name]" , type . Name ) ;
273- fromType = Array . Find ( types , it => it . Name == name ) ;
283+ fromType = types . FirstOrDefault ( it => it . Name == name ) ;
274284 }
275285
276286 return fromType ;
277287 }
278288
279- private static Type ? GetToType ( Type type , BaseAdaptAttribute attr , Type [ ] types )
289+ private static Type ? GetToType ( Type type , BaseAdaptAttribute attr , HashSet < Type > types )
280290 {
281291 if ( ! ( attr is AdaptToAttribute ) )
282292 return null ;
@@ -285,7 +295,7 @@ private static Type GetPropertyType(MemberInfo member, Type propType, Type attrT
285295 if ( toType == null && attr . Name != null )
286296 {
287297 var name = attr . Name . Replace ( "[name]" , type . Name ) ;
288- toType = Array . Find ( types , it => it . Name == name ) ;
298+ toType = types . FirstOrDefault ( it => it . Name == name ) ;
289299 }
290300
291301 return toType ;
@@ -322,7 +332,15 @@ private static void GenerateExtensions(ExtensionOptions opt)
322332 var codeGenConfig = new CodeGenerationConfig ( ) ;
323333 codeGenConfig . Scan ( assembly ) ;
324334
325- var types = assembly . GetTypes ( ) ;
335+ var assemblies = new HashSet < Assembly > { assembly } ;
336+ foreach ( var builder in codeGenConfig . AdaptAttributeBuilders )
337+ {
338+ foreach ( var setting in builder . TypeSettings )
339+ {
340+ assemblies . Add ( setting . Key . Assembly ) ;
341+ }
342+ }
343+ var types = assemblies . SelectMany ( it => it . GetTypes ( ) ) . ToHashSet ( ) ;
326344 var configDict = new Dictionary < BaseAdaptAttribute , TypeAdapterConfig > ( ) ;
327345 foreach ( var builder in codeGenConfig . AdaptAttributeBuilders )
328346 {
0 commit comments