private static ICode GenerateClientServiceProviderFactory( DependencyInjectionDescriptor descriptor) { CodeBlockBuilder codeBuilder = CodeBlockBuilder.New(); if (descriptor.TransportProfiles.Count == 1) { return(codeBuilder .AddCode( MethodCallBuilder .New() .SetMethodName("ConfigureClient" + descriptor.TransportProfiles[0].Name) .AddArgument(_sp) .AddArgument(_serviceCollection) .AddArgument(_strategy)) .AddEmptyLine() .AddCode(MethodCallBuilder .New() .SetReturn() .SetNew() .SetMethodName("ClientServiceProvider") .SetWrapArguments() .AddArgument(MethodCallBuilder .Inline() .SetMethodName(TypeNames.BuildServiceProvider) .AddArgument(_serviceCollection)))); } IfBuilder ifProfile = IfBuilder.New(); var enumName = CreateProfileEnumReference(descriptor); for (var index = 0; index < descriptor.TransportProfiles.Count; index++) { TransportProfile profile = descriptor.TransportProfiles[index]; IfBuilder currentIf = ifProfile; if (index != 0) { currentIf = IfBuilder.New(); ifProfile.AddIfElse(currentIf); } currentIf .SetCondition($"{_profile} == {enumName}.{profile.Name}") .AddCode( MethodCallBuilder .New() .SetMethodName("ConfigureClient" + profile.Name) .AddArgument(_sp) .AddArgument(_serviceCollection) .AddArgument(_strategy)); } return(codeBuilder .AddCode(ifProfile) .AddEmptyLine() .AddCode(MethodCallBuilder .New() .SetReturn() .SetNew() .SetMethodName("ClientServiceProvider") .SetWrapArguments() .AddArgument(MethodCallBuilder .Inline() .SetMethodName(TypeNames.BuildServiceProvider) .AddArgument(_serviceCollection)))); }