public IEnumerable <string> GenerateSource(TypeInfo typeInfo, out string fullClassName)
        {
            if (!typeInfo.IsInterface || !typeInfo.IsPublic)
            {
                throw new ArgumentException($"{typeInfo.FullName} must be a public interface");
            }

            if (typeInfo.IsGenericType)
            {
                throw new NotSupportedException($"Generic interfaces are not supported: {typeInfo.FullName}");
            }

            var className = typeInfo.FullName?.Replace(".", string.Empty);

            fullClassName = $"{Config.RootNamespace}.{className}";

            using (logger.BeginScope("Generator {0}:", className))
            {
                var serviceName  = typeInfo.GetCustomAttribute <FauxClientAttribute>().Name;
                var baseRoute    = typeInfo.GetCustomAttribute <FauxClientAttribute>().Route ?? string.Empty;
                var sealedString = Config.GenerateSealedClasses ? "sealed" : string.Empty;

                logger.LogTrace("Beginning to generate source");

                using (var namespaceBuilder = new IndentBuilder())
                {
                    namespaceBuilder.AppendLine($"namespace {Config.RootNamespace}");
                    namespaceBuilder.AppendLine("{");
                    using (var classBuilder = namespaceBuilder.Indent())
                    {
                        classBuilder.AppendLine("// Generated by DHaven.Faux");
                        classBuilder.AppendLine(
                            $"public {sealedString} class {className} : DHaven.Faux.HttpSupport.DiscoveryAwareBase, {typeInfo.FullName}");
                        classBuilder.AppendLine("{");

                        using (var fieldBuilder = classBuilder.Indent())
                        {
                            fieldBuilder.AppendLine("private readonly Microsoft.Extensions.Logging.ILogger 仮logger;");
                        }

                        using (var constructorBuilder = classBuilder.Indent())
                        {
                            constructorBuilder.AppendLine($"public {className}(DHaven.Faux.HttpSupport.IHttpClient client,");
                            constructorBuilder.AppendLine("        Microsoft.Extensions.Logging.ILogger logger)");
                            constructorBuilder.AppendLine($"    : base(client, \"{serviceName}\", \"{baseRoute}\")");
                            constructorBuilder.AppendLine("{");
                            using (var insideCxrBuilder = constructorBuilder.Indent())
                            {
                                insideCxrBuilder.AppendLine("仮logger = logger;");
                            }

                            constructorBuilder.AppendLine("}");
                        }

                        foreach (var method in typeInfo.GetMethods())
                        {
                            using (var methodBuilder = classBuilder.Indent())
                            {
                                BuildMethod(methodBuilder, method);
                            }
                        }

                        classBuilder.AppendLine("}");
                    }

                    namespaceBuilder.AppendLine("}");

                    var sourceCode = namespaceBuilder.ToString();

                    logger.LogTrace("Source generated");

                    if (Config.OutputSourceFiles)
                    {
                        var fullPath = Path.Combine(Config.SourceFilePath, $"{className}.cs");
                        try
                        {
                            logger.LogTrace("Writing source file: {0}", fullPath);
                            File.WriteAllText(fullPath, sourceCode, Encoding.UTF8);
                        }
                        catch (Exception ex)
                        {
                            logger.LogWarning(ex, "Could not write the source code for {0}", fullPath);
                        }
                    }

                    return(new[] { sourceCode });
                }
            }
        }
        public string GenerateMethodClass(MethodInfo method, out string fullMethodClassName)
        {
            var typeInfo = method.DeclaringType;

            Debug.Assert(typeInfo != null, nameof(typeInfo) + " is null");
            var className = $"{typeInfo.FullName?.Replace(".", string.Empty)}_{method.Name}";

            fullMethodClassName = $"{Config.RootNamespace}.{className}";
            var sealedString = Config.GenerateSealedClasses ? "sealed" : string.Empty;
            var isAsyncCall  = typeof(Task).IsAssignableFrom(method.ReturnType);
            var returnType   = method.ReturnType;
            var serviceName  = typeInfo.GetCustomAttribute <FauxClientAttribute>().Name;

            if (isAsyncCall && method.ReturnType.IsConstructedGenericType)
            {
                returnType = method.ReturnType.GetGenericArguments()[0];
            }

            var isVoid  = returnType == typeof(void) || (isAsyncCall && !method.ReturnType.IsConstructedGenericType);
            var treturn = isVoid ? string.Empty : $"<{CompilerUtils.ToCompilableName(returnType)}>";

            var inParams  = method.GetParameters().Where(p => !p.IsOut).ToList();
            var outParams = method.GetParameters().Where(p => p.IsOut).ToList();
            var attribute = method.GetCustomAttribute <HttpMethodAttribute>();

            using (logger.BeginScope("Generator {0}.{1}:", className, method.Name))
                using (var namespaceBuilder = new IndentBuilder())
                {
                    namespaceBuilder.AppendLine($"namespace {Config.RootNamespace}");
                    namespaceBuilder.AppendLine("{");
                    using (var classBuilder = namespaceBuilder.Indent())
                    {
                        classBuilder.AppendLine("// Generated by DHaven.Faux");
                        classBuilder.AppendLine($"public {sealedString} class {className} : Steeltoe.CircuitBreaker.Hystrix.HystrixCommand{treturn}");
                        classBuilder.AppendLine("{");
                        using (var fieldBuilder = classBuilder.Indent())
                        {
                            fieldBuilder.AppendLine("private readonly DHaven.Faux.HttpSupport.DiscoveryAwareBase 仮core;");
                            fieldBuilder.AppendLine("private readonly Microsoft.Extensions.Logging.ILogger 仮logger;");
                            fieldBuilder.AppendLine($"private readonly {typeInfo.FullName} 仮fallback;");

                            foreach (var inField in inParams)
                            {
                                fieldBuilder.AppendLine($"private readonly {CompilerUtils.ToCompilableName(inField.ParameterType)} {inField.Name};");
                            }
                        }

                        using (var constructorBuilder = classBuilder.Indent())
                        {
                            constructorBuilder.AppendLine($"public {className}(");
                            constructorBuilder.AppendLine("        DHaven.Faux.HttpSupport.DiscoveryAwareBase core,");
                            constructorBuilder.AppendLine($"        {typeInfo.FullName} fallback,");
                            foreach (var inparam in inParams)
                            {
                                constructorBuilder.AppendLine(
                                    $"        {CompilerUtils.ToCompilableName(inparam.ParameterType)} {inparam.Name},");
                            }
                            constructorBuilder.AppendLine("        Microsoft.Extensions.Logging.ILogger logger)");
                            constructorBuilder.AppendLine($"    : base(new Steeltoe.CircuitBreaker.Hystrix.HystrixCommandOptions(Steeltoe.CircuitBreaker.Hystrix.HystrixCommandGroupKeyDefault.AsKey(\"{serviceName}\"), Steeltoe.CircuitBreaker.Hystrix.HystrixCommandKeyDefault.AsKey(\"{method.Name}\")), null, null, logger)");
                            constructorBuilder.AppendLine("{");
                            using (var insideBuilder = constructorBuilder.Indent())
                            {
                                insideBuilder.AppendLine("仮core = core;");
                                insideBuilder.AppendLine("仮logger = logger;");
                                insideBuilder.AppendLine("仮fallback = fallback;");
                                foreach (var inparam in inParams)
                                {
                                    insideBuilder.AppendLine($"this.{inparam.Name} = {inparam.Name};");
                                }
                            }
                            constructorBuilder.AppendLine("}");
                        }

                        using (var propertyBuilder = classBuilder.Indent())
                        {
                            foreach (var property in outParams)
                            {
                                propertyBuilder.AppendLine($"public {CompilerUtils.ToCompilableName(property.ParameterType)} {property.Name} {{ get; private set; }}");
                            }
                        }

                        var taskType = isVoid ? "System.Reactive.Unit" : CompilerUtils.ToCompilableName(returnType);

                        using (var runBuilder = classBuilder.Indent())
                        {
                            runBuilder.AppendLine($"protected override async System.Threading.Tasks.Task<{taskType}> RunAsync()");
                            runBuilder.AppendLine("{");

                            using (var contentBuilder = runBuilder.Indent())
                            {
                                contentBuilder.AppendLine("var 仮variables = new System.Collections.Generic.Dictionary<string,object>();");
                                contentBuilder.AppendLine("var 仮reqParams = new System.Collections.Generic.Dictionary<string,string>();");

                                var           contentHeaders  = new Dictionary <string, ParameterInfo>();
                                var           requestHeaders  = new Dictionary <string, ParameterInfo>();
                                var           responseHeaders = new Dictionary <string, ParameterInfo>();
                                ParameterInfo bodyParam       = null;
                                BodyAttribute bodyAttr        = null;

                                foreach (var parameter in method.GetParameters())
                                {
                                    AttributeInterpreter.InterpretPathValue(parameter, contentBuilder);
                                    AttributeInterpreter.InterpretRequestHeader(parameter, requestHeaders, contentHeaders);
                                    AttributeInterpreter.InterpretBodyParameter(parameter, ref bodyParam, ref bodyAttr);
                                    AttributeInterpreter.InterpretRequestParameter(parameter, contentBuilder);
                                    AttributeInterpreter.InterpretResponseHeaderInParameters(parameter, false, ref responseHeaders);
                                }

                                contentBuilder.AppendLine($"var 仮request = 仮core.CreateRequest({CompilerUtils.ToCompilableName(attribute.Method)}, \"{attribute.Path}\", 仮variables, 仮reqParams);");
                                var hasContent =
                                    AttributeInterpreter.CreateContentObjectIfSpecified(bodyAttr, bodyParam, contentBuilder);

                                foreach (var entry in requestHeaders)
                                {
                                    contentBuilder.AppendLine($"仮request.Headers.Add(\"{entry.Key}\", {entry.Value.Name}{(entry.Value.ParameterType.IsClass ? "?" : "")}.ToString());");
                                }

                                if (hasContent)
                                {
                                    // when setting content we can apply the contentHeaders
                                    foreach (var entry in contentHeaders)
                                    {
                                        contentBuilder.AppendLine($"仮content.Headers.Add(\"{entry.Key}\", {entry.Value.Name}{(entry.Value.ParameterType.IsClass ? "?" : "")}.ToString());");
                                    }

                                    contentBuilder.AppendLine("仮request.Content = 仮content;");
                                }

                                contentBuilder.AppendLine("var 仮response = await 仮core.InvokeAsync(仮request);");

                                foreach (var entry in responseHeaders)
                                {
                                    contentBuilder.AppendLine(
                                        $"{entry.Value.Name} = DHaven.Faux.HttpSupport.DiscoveryAwareBase.GetHeaderValue<{CompilerUtils.ToCompilableName(entry.Value.ParameterType)}>(仮response, \"{entry.Key}\");");
                                }

                                if (isVoid)
                                {
                                    contentBuilder.AppendLine("return System.Reactive.Unit.Default;");
                                }
                                else
                                {
                                    var returnBodyAttribute     = method.ReturnParameter?.GetCustomAttribute <BodyAttribute>();
                                    var returnResponseAttribute =
                                        method.ReturnParameter?.GetCustomAttribute <ResponseHeaderAttribute>();

                                    if (returnResponseAttribute != null && returnBodyAttribute != null)
                                    {
                                        throw new WebServiceCompileException(
                                                  $"Cannot have different types of response attributes.  You had [{string.Join(", ", "Body", "ResponseHeader")}]");
                                    }

                                    if (returnResponseAttribute != null)
                                    {
                                        AttributeInterpreter.ReturnResponseHeader(returnResponseAttribute, returnType,
                                                                                  contentBuilder);
                                    }
                                    else
                                    {
                                        if (returnBodyAttribute == null)
                                        {
                                            returnBodyAttribute = new BodyAttribute();
                                        }

                                        AttributeInterpreter.ReturnContentObject(returnBodyAttribute, returnType, isAsyncCall,
                                                                                 contentBuilder);
                                    }
                                }
                            }

                            runBuilder.AppendLine("}");
                        }

                        using (var fallbackBuilder = classBuilder.Indent())
                        {
                            fallbackBuilder.AppendLine($"protected override async System.Threading.Tasks.Task<{taskType}> RunFallbackAsync()");
                            fallbackBuilder.AppendLine("{");

                            using (var contentBuilder = fallbackBuilder.Indent())
                            {
                                foreach (var value in outParams)
                                {
                                    contentBuilder.AppendLine($"{CompilerUtils.ToCompilableName(value.ParameterType)} {value.Name} = default({CompilerUtils.ToCompilableName(value.ParameterType)});");
                                }

                                if (!isVoid)
                                {
                                    contentBuilder.Append("var 仮value = ");
                                }

                                if (isAsyncCall)
                                {
                                    contentBuilder.Append("await ");
                                }

                                contentBuilder.Append($"仮fallback?.{method.Name}(");
                                contentBuilder.Append(string.Join(", ",
                                                                  method.GetParameters().Select(CompilerUtils.ToParameterUsage)));
                                contentBuilder.Append(")");
                                if (!isVoid && method.ReturnType.IsValueType)
                                {
                                    contentBuilder.Append($" ?? default({CompilerUtils.ToCompilableName(method.ReturnType)})");
                                }
                                contentBuilder.AppendLine(";");

                                foreach (var value in outParams)
                                {
                                    contentBuilder.AppendLine($"this.{value.Name} = {value.Name};");
                                }

                                var returnVal = isVoid ? "System.Reactive.Unit.Default" : "仮value";
                                contentBuilder.AppendLine($"return {returnVal};");
                            }

                            fallbackBuilder.AppendLine("}");
                        }

                        classBuilder.AppendLine("}");
                    }

                    namespaceBuilder.AppendLine("}");

                    var sourceCode = namespaceBuilder.ToString();

                    logger.LogTrace("Source generated");

                    if (Config.OutputSourceFiles)
                    {
                        var fullPath = Path.Combine(Config.SourceFilePath, $"{className}.cs");
                        try
                        {
                            logger.LogTrace("Writing source file: {0}", fullPath);
                            File.WriteAllText(fullPath, sourceCode, Encoding.UTF8);
                        }
                        catch (Exception ex)
                        {
                            logger.LogWarning(ex, "Could not write the source code for {0}", fullPath);
                        }
                    }

                    return(sourceCode);
                }
        }
        public IEnumerable <string> GenerateSource(TypeInfo typeInfo, out string fullClassName)
        {
            if (!typeInfo.IsInterface || !typeInfo.IsPublic)
            {
                throw new ArgumentException($"{typeInfo.FullName} must be a public interface");
            }

            if (typeInfo.IsGenericType)
            {
                throw new NotSupportedException($"Generic interfaces are not supported: {typeInfo.FullName}");
            }

            var className = typeInfo.FullName?.Replace(".", string.Empty);

            fullClassName = $"{Config.RootNamespace}.{className}";
            var sourceCodeList = new List <string>();

            using (logger.BeginScope("Generator {0}:", className))
            {
                var serviceName   = typeInfo.GetCustomAttribute <FauxClientAttribute>().Name;
                var baseRoute     = typeInfo.GetCustomAttribute <FauxClientAttribute>().Route ?? string.Empty;
                var fallbackClass = typeInfo.GetCustomAttribute <HystrixFauxClientAttribute>().Fallback;
                var sealedString  = Config.GenerateSealedClasses ? "sealed" : string.Empty;

                logger.LogTrace("Beginning to generate source");

                using (var namespaceBuilder = new IndentBuilder())
                {
                    namespaceBuilder.AppendLine($"namespace {Config.RootNamespace}");
                    namespaceBuilder.AppendLine("{");
                    using (var classBuilder = namespaceBuilder.Indent())
                    {
                        classBuilder.AppendLine("// Generated by DHaven.Faux");
                        classBuilder.AppendLine(
                            $"public {sealedString} class {className} : DHaven.Faux.HttpSupport.DiscoveryAwareBase, {typeInfo.FullName}");
                        classBuilder.AppendLine("{");

                        using (var fieldBuilder = classBuilder.Indent())
                        {
                            fieldBuilder.AppendLine("private readonly Microsoft.Extensions.Logging.ILogger 仮logger;");
                            fieldBuilder.AppendLine($"private readonly {typeInfo.FullName} 仮fallback;");
                            fieldBuilder.AppendLine("private readonly Steeltoe.CircuitBreaker.Hystrix.IHystrixCommandGroupKey 仮groupKey;");
                        }

                        using (var constructorBuilder = classBuilder.Indent())
                        {
                            constructorBuilder.AppendLine($"public {className}(DHaven.Faux.HttpSupport.IHttpClient client,");
                            constructorBuilder.AppendLine("        Microsoft.Extensions.Logging.ILogger logger)");
                            constructorBuilder.AppendLine($"    : base(client, \"{serviceName}\", \"{baseRoute}\")");
                            constructorBuilder.AppendLine("{");
                            using (var insideCxrBuilder = constructorBuilder.Indent())
                            {
                                insideCxrBuilder.AppendLine("仮logger = logger;");
                                if (fallbackClass != null)
                                {
                                    insideCxrBuilder.AppendLine($"仮fallback = new {CompilerUtils.ToCompilableName(fallbackClass)}();");
                                }
                                insideCxrBuilder.AppendLine(
                                    $"仮groupKey = Steeltoe.CircuitBreaker.Hystrix.HystrixCommandGroupKeyDefault.AsKey(\"{serviceName}\");");
                            }

                            constructorBuilder.AppendLine("}");
                        }

                        foreach (var method in typeInfo.GetMethods())
                        {
                            sourceCodeList.Add(methodGenerator.GenerateMethodClass(method, out var hystrixCommandName));
                            BuildMethod(classBuilder.Indent(), method, hystrixCommandName);
                        }

                        classBuilder.AppendLine("}");
                    }

                    namespaceBuilder.AppendLine("}");

                    var sourceCode = namespaceBuilder.ToString();

                    logger.LogTrace("Source generated");

                    if (Config.OutputSourceFiles)
                    {
                        var fullPath = Path.Combine(Config.SourceFilePath, $"{className}.cs");
                        try
                        {
                            logger.LogTrace("Writing source file: {0}", fullPath);
                            File.WriteAllText(fullPath, sourceCode, Encoding.UTF8);
                        }
                        catch (Exception ex)
                        {
                            logger.LogWarning(ex, "Could not write the source code for {0}", fullPath);
                        }
                    }

                    sourceCodeList.Add(sourceCode);
                    return(sourceCodeList);
                }
            }
        }