3
3
using System . Collections . Generic ;
4
4
using System . Diagnostics . CodeAnalysis ;
5
5
using System . Text ;
6
+ using System . Text . Json . Serialization ;
6
7
7
- public class CsFunctionVariation : ICsFunction , ICloneable < CsFunctionVariation >
8
+ public class CsFunctionVariation : ICsFunction , ICloneable < CsFunctionVariation > , IHasIdentifier
8
9
{
9
- public CsFunctionVariation ( string exportedName , string name , string structName , CsFunctionKind kind , CsType returnType , List < CsParameterInfo > parameters , List < CsGenericParameterInfo > genericParameters , List < string > modifiers , List < string > attributes )
10
+ [ JsonConstructor ]
11
+ public CsFunctionVariation ( string identifier , string exportedName , string name , string structName , CsFunctionKind kind , CsType returnType , List < CsParameterInfo > parameters , List < CsGenericParameterInfo > genericParameters , List < string > modifiers , List < string > attributes )
10
12
{
13
+ Identifier = identifier ;
11
14
ExportedName = exportedName ;
12
15
Name = name ;
13
16
@@ -20,8 +23,9 @@ public CsFunctionVariation(string exportedName, string name, string structName,
20
23
Attributes = attributes ;
21
24
}
22
25
23
- public CsFunctionVariation ( string exportedName , string name , string structName , CsFunctionKind kind , CsType returnType )
26
+ public CsFunctionVariation ( string identifier , string exportedName , string name , string structName , CsFunctionKind kind , CsType returnType )
24
27
{
28
+ Identifier = identifier ;
25
29
ExportedName = exportedName ;
26
30
Name = name ;
27
31
StructName = structName ;
@@ -33,6 +37,8 @@ public CsFunctionVariation(string exportedName, string name, string structName,
33
37
Attributes = new ( ) ;
34
38
}
35
39
40
+ public string Identifier { get ; set ; }
41
+
36
42
public string ExportedName { get ; set ; }
37
43
38
44
public string Name { get ; set ; }
@@ -55,29 +61,79 @@ public CsFunctionVariation(string exportedName, string name, string structName,
55
61
56
62
#region IDs
57
63
58
- public string BuildSignatureIdentifier ( )
64
+ protected virtual string BuildFunctionSignature ( CsFunctionVariation variation , bool useAttributes , bool useNames , WriteFunctionFlags flags )
65
+ {
66
+ int offset = flags == WriteFunctionFlags . None ? 0 : 1 ;
67
+ StringBuilder sb = new ( ) ;
68
+ bool isFirst = true ;
69
+
70
+ if ( flags == WriteFunctionFlags . Extension )
71
+ {
72
+ isFirst = false ;
73
+ var first = variation . Parameters [ 0 ] ;
74
+ if ( useNames )
75
+ {
76
+ sb . Append ( $ "this { first . Type } { first . Name } ") ;
77
+ }
78
+ else
79
+ {
80
+ sb . Append ( $ "this { first . Type } ") ;
81
+ }
82
+ }
83
+
84
+ for ( int i = offset ; i < variation . Parameters . Count ; i ++ )
85
+ {
86
+ var param = variation . Parameters [ i ] ;
87
+
88
+ if ( param . DefaultValue != null )
89
+ continue ;
90
+
91
+ if ( ! isFirst )
92
+ sb . Append ( ", " ) ;
93
+
94
+ if ( useAttributes )
95
+ {
96
+ sb . Append ( $ "{ string . Join ( " " , param . Attributes ) } ") ;
97
+ }
98
+
99
+ sb . Append ( $ "{ param . Type } ") ;
100
+
101
+ if ( useNames )
102
+ {
103
+ sb . Append ( $ " { param . Name } ") ;
104
+ }
105
+
106
+ isFirst = false ;
107
+ }
108
+
109
+ return sb . ToString ( ) ;
110
+ }
111
+
112
+ public string BuildFunctionHeaderId ( WriteFunctionFlags flags )
59
113
{
60
- return $ "{ Name } { ( IsGeneric ? $ "<{ BuildGenericSignature ( ) } >" : string . Empty ) } ({ BuildSignature ( false , false ) } )";
114
+ string signature = BuildFunctionSignature ( this , false , false , flags ) ;
115
+ return Identifier = $ "{ Name } ({ signature } )";
61
116
}
62
117
63
- public string BuildConstructorSignatureIdentifier ( )
118
+ public string BuildFunctionHeader ( CsType csReturnType , WriteFunctionFlags flags , bool generateMetadata )
64
119
{
65
- return $ "{ StructName } ({ BuildConstructorSignature ( false , false , false ) } )";
120
+ string signature = BuildFunctionSignature ( this , generateMetadata , true , flags ) ;
121
+ return Identifier = $ "{ csReturnType . Name } { Name } ({ signature } )";
66
122
}
67
123
68
- public string BuildExtensionSignatureIdentifier ( string type )
124
+ public string BuildConstructorSignatureIdentifier ( )
69
125
{
70
- return $ " { Name } { ( IsGeneric ? $ "< { BuildGenericSignature ( ) } >" : string . Empty ) } ( { BuildExtensionSignature ( type , null , false , false ) } )";
126
+ return Identifier = $ "{ StructName } ( { BuildConstructorSignature ( false , false , false ) } )";
71
127
}
72
128
73
129
public string BuildSignatureIdentifierForCOM ( )
74
130
{
75
- return $ "{ ReturnType . Name } { Name } { ( IsGeneric ? $ "<{ BuildGenericSignature ( ) } >" : string . Empty ) } ({ BuildSignature ( false , false ) } )";
131
+ return Identifier = $ "{ ReturnType . Name } { Name } { ( IsGeneric ? $ "<{ BuildGenericSignature ( ) } >" : string . Empty ) } ({ BuildSignature ( false , false ) } )";
76
132
}
77
133
78
134
public string BuildExtensionSignatureIdentifierForCOM ( string comObject )
79
135
{
80
- return $ "{ ReturnType . Name } { Name } { ( IsGeneric ? $ "<{ BuildGenericSignature ( ) } >" : string . Empty ) } ({ BuildExtensionSignatureForCOM ( comObject , false , false ) } )";
136
+ return Identifier = $ "{ ReturnType . Name } { Name } { ( IsGeneric ? $ "<{ BuildGenericSignature ( ) } >" : string . Empty ) } ({ BuildExtensionSignatureForCOM ( comObject , false , false ) } )";
81
137
}
82
138
83
139
#endregion IDs
@@ -230,12 +286,12 @@ public bool TryGetParameter(string name, [NotNullWhen(true)] out CsParameterInfo
230
286
231
287
public CsFunctionVariation ShallowClone ( )
232
288
{
233
- return new CsFunctionVariation ( ExportedName , Name , StructName , Kind , ReturnType . Clone ( ) ) ;
289
+ return new CsFunctionVariation ( Identifier , ExportedName , Name , StructName , Kind , ReturnType . Clone ( ) ) ;
234
290
}
235
291
236
292
public CsFunctionVariation Clone ( )
237
293
{
238
- return new CsFunctionVariation ( ExportedName , Name , StructName , Kind , ReturnType . Clone ( ) , Parameters . CloneValues ( ) , GenericParameters . CloneValues ( ) , Modifiers . Clone ( ) , Attributes . Clone ( ) ) ;
294
+ return new CsFunctionVariation ( Identifier , ExportedName , Name , StructName , Kind , ReturnType . Clone ( ) , Parameters . CloneValues ( ) , GenericParameters . CloneValues ( ) , Modifiers . Clone ( ) , Attributes . Clone ( ) ) ;
239
295
}
240
296
}
241
297
}
0 commit comments