public static void BuildOut(Type interfaceType, MethodInfo definition, GeneratedMethod generated) { var path = definition.GetCustomAttribute <PathAttribute>(); generated.Frames.Add(new BuildClientFrame(interfaceType)); var urlFrame = new FillUrlFrame(definition); generated.Frames.Add(urlFrame); var inputType = DetermineRequestType(definition); if (inputType == null) { generated.Frames.Add(new BuildRequestFrame(path.Method, urlFrame, null)); } else { var serializeFrame = new SerializeJsonFrame(inputType); generated.Frames.Add(serializeFrame); generated.Frames.Add(new BuildRequestFrame(path.Method, urlFrame, serializeFrame)); } generated.Frames.Call <HttpClient>(x => x.SendAsync(null)); var returnType = DetermineResponseType(definition); if (returnType != null) { var deserialize = new DeserializeObjectFrame(returnType); generated.Frames.Add(deserialize); generated.Frames.Return(deserialize.ReturnValue); } }
public static void BuildOut( // The contract type Type interfaceType, // The MethodInfo from Reflection that describes // the Url structure through attributes, the input type // if any, and the .Net type of the response (if any) MethodInfo definition, // This models the method being generated by LamarCompiler GeneratedMethod generated) { var path = definition.GetCustomAttribute <PathAttribute>(); // Get the right HttpClient from IHttpClientFactory generated.Frames.Add(new BuildClientFrame(interfaceType)); // Build out the Url from the method arguments and route // pattern var urlFrame = new FillUrlFrame(definition); generated.Frames.Add(urlFrame); // See if there is an input type that should be serialized // to the HTTP request body var inputType = DetermineRequestType(definition); if (inputType == null) { // Just build the HttpRequestMessage generated.Frames.Add(new BuildRequestFrame(path.Method, urlFrame, null)); } else { // Add a step to serialize the input model to Json generated.Frames.Add(new SerializeJsonFrame(inputType)); // Just build the HttpRequestMessage generated.Frames.Add(new BuildRequestFrame(path.Method, urlFrame, new SerializeJsonFrame(inputType))); } // Actually call the HttpClient to send the request generated.Frames.Call <HttpClient>(x => x.SendAsync(null)); // Is there a response type that should be serialized out of the HTTP // response body? var returnType = DetermineResponseType(definition); if (returnType != null) { // Deserialize the response JSON into a new variable var deserialize = new DeserializeObjectFrame(returnType); generated.Frames.Add(deserialize); // Return that deserialized object from the method generated.Frames.Return(deserialize.ReturnValue); } }