@@ -14,9 +14,16 @@ public class ReflectionModelReader
1414 {
1515 public ModelTransferObject Read ( Type type , List < ITransferObject > transferObjects , IFromTypeOptions options = null )
1616 {
17- bool isFromSystem = type . Namespace != null && type . Namespace . StartsWith ( "System" ) ;
1817 ModelTransferObject model = new ModelTransferObject { Language = ReflectionLanguage . Instance } ;
19- model . FromType ( type , options ) ;
18+ model . Name = model . OriginalName = type . Name ;
19+ model . Namespace = type . Namespace ;
20+ model . IsNullable = ! type . IsValueType ;
21+ model . IsGeneric = type . IsGenericType ;
22+ model . FromSystem = type . Namespace != null && type . Namespace . StartsWith ( "System" ) ;
23+ if ( model . IsGeneric )
24+ {
25+ model . Name = type . Name . Split ( '`' ) . First ( ) ;
26+ }
2027 ModelTransferObject existingModel = transferObjects . OfType < ModelTransferObject > ( ) . FirstOrDefault ( entry => entry . Equals ( model ) ) ;
2128 if ( existingModel != null )
2229 {
@@ -31,7 +38,7 @@ public ModelTransferObject Read(Type type, List<ITransferObject> transferObjects
3138 {
3239 this . ReadArray ( type , model , transferObjects ) ;
3340 }
34- else if ( type . IsGenericType && isFromSystem )
41+ else if ( type . IsGenericType && model . FromSystem )
3542 {
3643 this . ReadGenericFromSystem ( type , model , transferObjects ) ;
3744 }
@@ -43,31 +50,44 @@ public ModelTransferObject Read(Type type, List<ITransferObject> transferObjects
4350 else if ( type . ContainsGenericParameters )
4451 {
4552 model . HasUsing = false ;
53+ model . Namespace = null ;
4654 }
47- else if ( ! isFromSystem )
55+ else if ( ! model . FromSystem )
4856 {
4957 transferObjects . Add ( model ) ;
5058 this . ReadClass ( type , model , transferObjects ) ;
5159 }
60+ if ( model . Name == nameof ( Nullable ) )
61+ {
62+ model . IsNullable = true ;
63+ }
64+ if ( ! model . FromSystem && options ? . ReplaceName != null )
65+ {
66+ for ( int index = 0 ; index < options . ReplaceName . Count ; index ++ )
67+ {
68+ string replaceName = options . ReplaceName [ index ] ;
69+ string replaceWith = options . ReplaceWithName ? . Skip ( index ) . FirstOrDefault ( ) ?? string . Empty ;
70+ model . Name = model . Name . Replace ( replaceName , replaceWith ) ;
71+ }
72+ }
5273 return model ;
5374 }
5475
5576 private void ReadArray ( Type type , ModelTransferObject model , List < ITransferObject > transferObjects )
5677 {
5778 Logger . Trace ( $ "Reflection read array { type . Name } ({ type . Namespace } )") ;
79+ model . Name = "Array" ;
5880 model . IsGeneric = true ;
59- model . FromSystem = true ;
60- this . Read ( type . GetElementType ( ) , transferObjects ) ;
81+ model . HasUsing = false ;
82+ model . Generics . Add ( new GenericAliasTransferObject { Type = this . Read ( type . GetElementType ( ) , transferObjects ) } ) ;
6183 }
6284
6385 private void ReadGenericFromSystem ( Type type , ModelTransferObject model , List < ITransferObject > transferObjects )
6486 {
6587 Logger . Trace ( $ "Reflection read generic system type { type . Name } <{ string . Join ( "," , type . GetGenericArguments ( ) . Select ( x => x . Name ) ) } > ({ type . Namespace } )") ;
66- model . IsGeneric = true ;
67- model . FromSystem = true ;
6888 foreach ( Type argument in type . GenericTypeArguments )
6989 {
70- this . Read ( argument , transferObjects ) ;
90+ model . Generics . Add ( new GenericAliasTransferObject { Type = this . Read ( argument , transferObjects ) } ) ;
7191 }
7292 }
7393
@@ -104,17 +124,16 @@ private void ReadClass(Type type, ModelTransferObject model, List<ITransferObjec
104124 if ( type . IsGenericType )
105125 {
106126 Type genericType = type . GetGenericTypeDefinition ( ) ;
107- model . IsGeneric = true ;
108127 model . Generics . Clear ( ) ;
109128 if ( genericType is TypeInfo typeInfo )
110129 {
111130 for ( int index = 0 ; index < typeInfo . GenericTypeParameters . Length ; index ++ )
112131 {
113- string alias = typeInfo . GenericTypeParameters [ index ] . Name ;
132+ Type alias = typeInfo . GenericTypeParameters [ index ] ;
114133 Type argument = type . GenericTypeArguments [ index ] ;
115134 model . Generics . Add ( new GenericAliasTransferObject
116135 {
117- Alias = alias ,
136+ Alias = this . Read ( alias , transferObjects ) ,
118137 Type = this . Read ( argument , transferObjects )
119138 } ) ;
120139 }
0 commit comments