@@ -64,64 +64,36 @@ private string GetSerializationMethodsForPrimitiveUnionTypes(CodeComposedTypeBas
64
64
return codeElement . OriginalLocalMethod . Parameters . FirstOrDefault ( x => GetOriginalComposedType ( x ) is not null ) ;
65
65
}
66
66
67
- private void WriteComposedTypeDeserializer ( CodeFunction codeElement , LanguageWriter writer , CodeParameter composedParam )
68
- {
69
-
70
- if ( GetOriginalComposedType ( composedParam ) is not { } composedType ) return ;
71
-
72
- writer . StartBlock ( "return {" ) ;
73
- foreach ( var mappedType in composedType . Types . Where ( x => ! conventions . IsPrimitiveType ( x , composedType , false ) ) )
74
- {
75
- var functionName = GetDeserializerFunctionName ( codeElement , mappedType ) ;
76
- var variableName = composedParam . Name . ToFirstCharacterLowerCase ( ) ;
77
- var variableType = conventions . GetTypeString ( mappedType , codeElement , includeCollectionInformation : false ) ;
78
-
79
- writer . WriteLine ( $ "...{ functionName } ({ variableName } as { variableType } ),") ;
80
- }
81
- writer . CloseBlock ( ) ;
82
- }
83
-
84
67
private void WriteComposedTypeSerializer ( CodeFunction codeElement , LanguageWriter writer , CodeParameter composedParam )
85
68
{
86
69
if ( GetOriginalComposedType ( composedParam ) is not { } composedType ) return ;
87
-
88
- if ( composedType . IsComposedOfPrimitives ( ( x , y ) => conventions . IsPrimitiveType ( x , y , false ) ) )
89
- {
70
+
71
+ if ( composedParam . Type is CodeType codeType && codeType . TypeDefinition is CodeInterface codeInterface )
72
+ {
90
73
var paramName = composedParam . Name . ToFirstCharacterLowerCase ( ) ;
91
74
writer . WriteLine ( $ "if ({ paramName } === undefined || { paramName } === null) return;") ;
92
- writer . StartBlock ( $ "switch (true) {{") ;
93
- foreach ( var type in composedType . Types . Where ( x => conventions . IsPrimitiveType ( x , composedType , false ) ) )
94
- {
95
- WriteCaseStatementForPrimitiveTypeSerialization ( type , paramName , codeElement , writer ) ;
96
- }
97
- writer . CloseBlock ( ) ;
75
+ codeInterface . Properties
76
+ . Select ( property => property . Name . ToFirstCharacterLowerCase ( ) )
77
+ . ToList ( )
78
+ . ForEach ( codePropertyName =>
79
+ {
80
+ writer . StartBlock ( $ "if ({ paramName } .{ codePropertyName } ) {{") ;
81
+ WritePropertySerializer ( paramName , codeInterface . Properties . First ( p => p . Name . ToFirstCharacterLowerCase ( ) == codePropertyName ) , writer , codeElement ) ;
82
+ writer . CloseBlock ( ) ;
83
+ } ) ;
98
84
return ;
99
85
}
100
86
101
87
if ( composedType is CodeIntersectionType )
102
88
{
89
+ // fix me
103
90
WriteSerializationFunctionForCodeIntersectionType ( composedType , composedParam , codeElement , writer ) ;
104
91
return ;
105
92
}
106
93
107
94
WriteSerializationFunctionForCodeUnionTypes ( composedType , composedParam , codeElement , writer ) ;
108
95
}
109
96
110
- private void WriteCaseStatementForPrimitiveTypeSerialization ( CodeTypeBase type , String paramName , CodeFunction method , LanguageWriter writer )
111
- {
112
- var nodeType = conventions . GetTypeString ( type , method , false ) ;
113
- var collectionNodeType = conventions . GetTypeString ( type , method , true ) ;
114
- var serializationName = GetSerializationMethodName ( type , method . OriginalLocalMethod ) ;
115
- if ( string . IsNullOrEmpty ( serializationName ) || string . IsNullOrEmpty ( nodeType ) ) return ;
116
-
117
- writer . StartBlock ( type . IsCollection
118
- ? $ "case Array.isArray({ paramName } ) :"
119
- : $ "case typeof { paramName } === \" { nodeType } \" :") ;
120
-
121
- writer . WriteLine ( $ "writer.{ serializationName } (undefined, { paramName } as { collectionNodeType } );") ;
122
- writer . CloseBlock ( "break;" ) ;
123
- }
124
-
125
97
private void WriteSerializationFunctionForCodeIntersectionType ( CodeComposedTypeBase composedType , CodeParameter composedParam , CodeFunction method , LanguageWriter writer )
126
98
{
127
99
// Serialization/Deserialization functions can be called for object types only
0 commit comments