1- #if ! CASTLE && ! DISPATCH_PROXY
2- using System ;
1+ using System ;
2+ using System . Collections . Generic ;
33using System . Linq ;
44using System . Reflection ;
5+ using System . Runtime . CompilerServices ;
6+ using System . Threading . Tasks ;
7+ using WampSharp . Core . Utilities . ValueTuple ;
8+ using TaskExtensions = WampSharp . Core . Utilities . TaskExtensions ;
59
610namespace WampSharp . CodeGeneration
711{
@@ -96,6 +100,51 @@ private static string Prettify(string fullName)
96100
97101 return result ;
98102 }
103+
104+ public static string GetFormattedReturnType ( MethodInfo method )
105+ {
106+ if ( ! method . ReturnsTuple ( ) )
107+ {
108+ return FormatType ( method . ReturnType ) ;
109+ }
110+ else
111+ {
112+ Type returnType = TaskExtensions . UnwrapReturnType ( method . ReturnType ) ;
113+
114+ IEnumerable < Type > tupleElementTypes =
115+ returnType . GetValueTupleElementTypes ( ) ;
116+
117+ TupleElementNamesAttribute tupleElementNamesAttribute =
118+ method . ReturnParameter . GetCustomAttribute < TupleElementNamesAttribute > ( ) ;
119+
120+ IEnumerable < string > tupleElementsIdentifiers ;
121+
122+ IEnumerable < string > tupleElementTypesIdentifiers = tupleElementTypes
123+ . Select ( x => FormatType ( x ) ) ;
124+
125+ if ( tupleElementNamesAttribute == null )
126+ {
127+ tupleElementsIdentifiers = tupleElementTypesIdentifiers ;
128+ }
129+ else
130+ {
131+ tupleElementsIdentifiers =
132+ tupleElementTypesIdentifiers
133+ . Zip ( tupleElementNamesAttribute . TransformNames ,
134+ ( type , name ) => $ "{ type } { name } ") ;
135+ }
136+
137+ string tupleIdentifierContent = string . Join ( ", " , tupleElementsIdentifiers ) ;
138+
139+ if ( typeof ( Task ) . IsAssignableFrom ( method . ReturnType ) )
140+ {
141+ return $ "Task<({ tupleIdentifierContent } )>";
142+ }
143+ else
144+ {
145+ return $ "({ tupleIdentifierContent } )";
146+ }
147+ }
148+ }
99149 }
100- }
101- #endif
150+ }
0 commit comments