< Summary - CoreWCF Coverage — PR #1766

Line coverage
92%
Covered lines: 244
Uncovered lines: 19
Coverable lines: 263
Total lines: 588
Line coverage: 92.7%
Branch coverage
83%
Covered branches: 94
Total branches: 112
Branch coverage: 83.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.BuildTools/src/OperationInvokerGenerator.Emitter.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections.Generic;
 5using System.Text;
 6using Microsoft.CodeAnalysis;
 7using Microsoft.CodeAnalysis.CSharp;
 8using Microsoft.CodeAnalysis.Text;
 9
 10namespace CoreWCF.BuildTools;
 11
 12public sealed partial class OperationInvokerGenerator
 13{
 14    private sealed class Emitter
 15    {
 16        private readonly StringBuilder _builder;
 17        private readonly OperationInvokerSourceGenerationContext _sourceGenerationContext;
 18        private readonly SourceGenerationSpec _generationSpec;
 19
 20        /// <summary>
 21        /// SymbolDisplayFormat that excludes nullable annotations to match reflection-based key generation.
 22        /// Reflection-based MethodInfo does not expose nullable reference type annotations, so we need to
 23        /// exclude them from the generated key to ensure the source generator key matches the runtime key.
 24        /// This prevents PlatformNotSupportedException when UseGeneratedOperationInvokers is enabled.
 25        /// </summary>
 126        private static readonly SymbolDisplayFormat s_methodDisplayFormat = new SymbolDisplayFormat(
 127            globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
 128            typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
 129            genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
 130            memberOptions: SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeContainingTy
 131            parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeParamsRef
 132            miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes);
 33
 34        /// <summary>
 35        /// SymbolDisplayFormat for emitting type references in generated code. Mirrors the default
 36        /// CSharpErrorMessageFormat but strips nullable reference type annotations because the generated
 37        /// file is wrapped in a '#nullable disable' context. Emitting NRT annotations like 'string?' under
 38        /// '#nullable disable' produces CS8669 warnings (see issue #1712). Nullable value types such as
 39        /// 'int?' are unaffected because they are System.Nullable&lt;T&gt; rather than NRT annotations.
 40        /// </summary>
 141        private static readonly SymbolDisplayFormat s_typeDisplayFormat = SymbolDisplayFormat.CSharpErrorMessageFormat
 142            .RemoveMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier);
 43
 5244        public Emitter(in OperationInvokerSourceGenerationContext sourceGenerationContext, in SourceGenerationSpec gener
 45        {
 5246            _sourceGenerationContext = sourceGenerationContext;
 5247            _generationSpec = generationSpec;
 5248            _builder = new StringBuilder();
 5249        }
 50
 51        public void Emit()
 52        {
 5253            if (_generationSpec.OperationContractSpecs.Length == 0)
 54            {
 055                return;
 56            }
 5257            _builder.Clear();
 5258            _builder.AppendLine($$"""
 5259                                  // <auto-generated>
 5260                                  // Generated by the CoreWCF.BuildTools.OperationInvokerGenerator source generator. DO 
 5261                                  // </auto-generated>
 5262                                  #nullable disable
 5263                                  using System;
 5264                                  using System.Threading.Tasks;
 5265                                  namespace System.Runtime.CompilerServices
 5266                                  {
 5267                                      [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
 5268                                      file sealed class ModuleInitializerAttribute : Attribute { }
 5269                                  }
 5270                                  """);
 5271            int i = 0;
 22472            foreach (var operationContractSpec in _generationSpec.OperationContractSpecs)
 73            {
 6074                EmitOperationContract(operationContractSpec, i);
 6075                i++;
 76            }
 77
 5278            var indentor = new Indentor();
 5279            _builder.AppendLine($$"""
 5280                                  namespace CoreWCF.Dispatcher
 5281                                  {
 5282                                      file sealed class OperationInvokerModuleInitializer
 5283                                      {
 5284                                  """);
 5285            indentor.Increment();
 5286            indentor.Increment();
 87
 5288            _builder.AppendLine($"{indentor}[System.Runtime.CompilerServices.ModuleInitializer]");
 5289            _builder.AppendLine($"{indentor}internal static void RegisterOperationInvokers()");
 5290            _builder.AppendLine($"{indentor}{{");
 5291            indentor.Increment();
 22492            for (int j = 0; j < i; j++)
 93            {
 6094                _builder.AppendLine($"{indentor}{GetOperationInvokerTypeName(j)}.RegisterOperationInvoker();");
 95            }
 5296            indentor.Decrement();
 5297            _builder.AppendLine($"{indentor}}}");
 5298            indentor.Decrement();
 5299            _builder.AppendLine($"{indentor}}}");
 52100            indentor.Decrement();
 52101            _builder.AppendLine($"{indentor}}}");
 52102            _builder.AppendLine("#nullable restore");
 103
 52104            string sourceText = _builder.ToString();
 52105            _sourceGenerationContext.AddSource("OperationInvoker.g.cs", SourceText.From(sourceText, Encoding.UTF8, Sourc
 52106        }
 107
 108        private void EmitOperationContract(OperationContractSpec operationContractSpec, int index)
 109        {
 60110            var indentor = new Indentor();
 60111            string operationInvokerTypeName = GetOperationInvokerTypeName(index);
 60112            string escapedMethodName = EscapeIdentifier(operationContractSpec.Method!.Name);
 60113            _builder.AppendLine($$"""
 60114                                  namespace CoreWCF.Dispatcher
 60115                                  {
 60116                                      // This class is used to invoke the method {{operationContractSpec.Method.ToDispla
 60117                                      file sealed class {{operationInvokerTypeName}} : CoreWCF.Dispatcher.IOperationInvo
 60118                                      {
 60119                                  """);
 60120            indentor.Increment();
 60121            indentor.Increment();
 122
 60123            INamedTypeSymbol? returnTypeSymbol = operationContractSpec.Method!.ReturnType as INamedTypeSymbol;
 60124            bool isGenericTaskReturnType = returnTypeSymbol != null &&
 60125                                           returnTypeSymbol.IsGenericType &&
 60126                                           returnTypeSymbol.ConstructUnboundGenericType().ToDisplayString() == "System.T
 60127            bool isTaskReturnType = operationContractSpec.Method.ReturnType.ToDisplayString() == "System.Threading.Tasks
 60128            bool isAsync = isGenericTaskReturnType || isTaskReturnType;
 129
 60130            string asyncString = isAsync ? "async " : string.Empty;
 60131            _builder.AppendLine($"{indentor}public { asyncString }ValueTask<(object returnValue, object[] outputs)> Invo
 60132            _builder.AppendLine($"{indentor}{{");
 60133            indentor.Increment();
 134
 60135            int inputParameterCount = 0;
 60136            int outputParameterCount = 0;
 137
 60138            List<(int, int, IParameterSymbol)> outputParams = new();
 60139            int i = 0;
 60140            List<string> invocationParams = new();
 336141            foreach (var parameter in operationContractSpec.Method.Parameters)
 142            {
 108143                _builder.AppendLine($"{indentor}{parameter.Type.ToDisplayString(s_typeDisplayFormat)} p{i};");
 108144                if (FlowsIn(parameter))
 145                {
 88146                    _builder.AppendLine($"{indentor}p{i} = inputs[{inputParameterCount}] == null ? default({parameter.Ty
 88147                    inputParameterCount++;
 148                }
 149
 108150                if (FlowOut(parameter))
 151                {
 40152                    outputParams.Add((outputParameterCount, i, parameter));
 40153                    outputParameterCount++;
 154                }
 155
 108156                invocationParams.Add($"{GetRefKind(parameter)}p{i}");
 108157                i++;
 158            }
 159
 60160            if (isAsync)
 161            {
 8162                if (isTaskReturnType)
 163                {
 4164                    _builder.AppendLine($"{indentor}await (({operationContractSpec.Method.ContainingType.ToDisplayString
 165                }
 166                else
 167                {
 4168                    _builder.AppendLine($"{indentor}var result = await (({operationContractSpec.Method.ContainingType.To
 169                }
 170            }
 171            else
 172            {
 52173                if (operationContractSpec.Method.ReturnsVoid)
 174                {
 4175                    _builder.AppendLine($"{indentor}(({operationContractSpec.Method.ContainingType.ToDisplayString(s_typ
 176                }
 177                else
 178                {
 48179                    _builder.AppendLine($"{indentor}var result = (({operationContractSpec.Method.ContainingType.ToDispla
 180                }
 181            }
 182
 60183            _builder.AppendLine($"{indentor}var outputs = AllocateOutputs();");
 184
 200185            foreach (var (ouputIndex, parameterIndex, parameter) in outputParams)
 186            {
 40187                _builder.AppendLine($"{indentor}outputs[{ouputIndex}] = p{parameterIndex};");
 188            }
 189
 60190            if (isAsync)
 191            {
 8192                if (isTaskReturnType)
 193                {
 4194                    _builder.AppendLine($"{indentor}return (null, outputs);");
 195                }
 196                else
 197                {
 4198                    _builder.AppendLine($"{indentor}return (result, outputs);");
 199                }
 200            }
 201            else
 202            {
 52203                if (operationContractSpec.Method.ReturnsVoid)
 204                {
 4205                    _builder.AppendLine($"{indentor}return new ValueTask<(object, object[])>((null, outputs));");
 206                }
 207                else
 208                {
 48209                    _builder.AppendLine($"{indentor}return new ValueTask<(object, object[])>((result, outputs));");
 210                }
 211            }
 212
 60213            indentor.Decrement();
 60214            _builder.AppendLine($"{indentor}}}");
 60215            _builder.AppendLine();
 60216            _builder.Append($"{indentor}public object[] AllocateInputs() => ");
 60217            if (inputParameterCount == 0)
 218            {
 0219                _builder.AppendLine("Array.Empty<object>();");
 220            }
 221            else
 222            {
 60223                _builder.AppendLine($"new object[{inputParameterCount}];");
 224            }
 60225            _builder.AppendLine();
 60226            _builder.Append($"{indentor}private object[] AllocateOutputs() => ");
 60227            if (outputParameterCount == 0)
 228            {
 40229                _builder.AppendLine("Array.Empty<object>();");
 230            }
 231            else
 232            {
 20233                _builder.AppendLine($"new object[{outputParameterCount}];");
 234            }
 60235            _builder.AppendLine();
 236
 60237            _builder.Append($"{indentor}internal static void RegisterOperationInvoker() => ");
 60238            _builder.AppendLine($"CoreWCF.Dispatcher.DispatchOperationRuntimeHelpers.RegisterOperationInvoker(\"{operati
 60239            indentor.Decrement();
 60240            _builder.AppendLine($"{indentor}}}");
 241
 60242            indentor.Decrement();
 60243            _builder.AppendLine($"{indentor}}}");
 244
 245
 60246        }
 247
 120248        private static string GetOperationInvokerTypeName(int index) => $"OperationInvoker{index}";
 249
 250        private static string EscapeIdentifier(string identifier)
 251        {
 60252            return SyntaxFacts.GetKeywordKind(identifier) != SyntaxKind.None ||
 60253                   SyntaxFacts.GetContextualKeywordKind(identifier) != SyntaxKind.None
 60254                ? "@" + identifier
 60255                : identifier;
 256        }
 257
 258        private static bool FlowsIn(IParameterSymbol parameterSymbol)
 259        {
 108260            return parameterSymbol.RefKind == RefKind.In || parameterSymbol.RefKind == RefKind.Ref || parameterSymbol.Re
 261        }
 262
 263        private static bool FlowOut(IParameterSymbol parameterSymbol)
 264        {
 108265            return parameterSymbol.RefKind == RefKind.Out || parameterSymbol.RefKind == RefKind.Ref;
 266        }
 267
 268        private static string GetRefKind(IParameterSymbol parameterSymbol)
 269        {
 108270            return parameterSymbol.RefKind switch
 108271            {
 20272                RefKind.Ref => "ref ",
 20273                RefKind.Out => "out ",
 68274                _ => string.Empty,
 108275            };
 276        }
 277    }
 278}

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.BuildTools/src/OperationInvokerGenerator.OperationContractSpec.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using Microsoft.CodeAnalysis;
 5
 6namespace CoreWCF.BuildTools;
 7
 8public sealed partial class OperationInvokerGenerator
 9{
 10    internal readonly record struct OperationContractSpec(IMethodSymbol? Method)
 11    {
 58412        public IMethodSymbol? Method { get; } = Method;
 13    }
 14}

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.BuildTools/src/OperationInvokerGenerator.Parser.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Collections.Immutable;
 7using System.Linq;
 8using Microsoft.CodeAnalysis;
 9using Microsoft.CodeAnalysis.CSharp;
 10using Microsoft.CodeAnalysis.CSharp.Syntax;
 11
 12namespace CoreWCF.BuildTools;
 13
 14public sealed partial class OperationInvokerGenerator
 15{
 16    private sealed class Parser
 17    {
 118        private static readonly SymbolDisplayFormat s_methodDisplayFormat = new SymbolDisplayFormat(
 119            globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
 120            typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
 121            genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
 122            memberOptions: SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeContainingTy
 123            parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeParamsRef
 124            miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes);
 25
 26        private readonly Compilation _compilation;
 27        private readonly OperationInvokerSourceGenerationContext _context;
 28        private readonly INamedTypeSymbol? _sSMOperationContractSymbol;
 29        private readonly INamedTypeSymbol? _coreWCFOperationContractSymbol;
 30        private readonly INamedTypeSymbol? _sSMServiceContractSymbol;
 31        private readonly INamedTypeSymbol? _coreWCFServiceContractSymbol;
 32
 7633        public Parser(Compilation compilation, in OperationInvokerSourceGenerationContext context)
 34        {
 7635                _compilation = compilation;
 7636                _context = context;
 37
 7638                _sSMOperationContractSymbol = _compilation.GetTypeByMetadataName("System.ServiceModel.OperationContractA
 7639                _coreWCFOperationContractSymbol = _compilation.GetTypeByMetadataName("CoreWCF.OperationContractAttribute
 7640                _sSMServiceContractSymbol = _compilation.GetTypeByMetadataName("System.ServiceModel.ServiceContractAttri
 7641                _coreWCFServiceContractSymbol = _compilation.GetTypeByMetadataName("CoreWCF.ServiceContractAttribute");
 7642            }
 43
 44        public SourceGenerationSpec GetGenerationSpec(ImmutableArray<InterfaceDeclarationSyntax> interfaceDeclarationSyn
 45        {
 7646                var builder = ImmutableArray.CreateBuilder<OperationContractSpec>();
 7647                HashSet<string> emittedOperations = new(StringComparer.Ordinal);
 48
 7649                var serviceContracts = (from interfaceDeclarationSyntax in interfaceDeclarationSyntaxes
 9650                    let semanticModel = _compilation.GetSemanticModel(interfaceDeclarationSyntax.SyntaxTree)
 9651                    let symbol = semanticModel.GetDeclaredSymbol(interfaceDeclarationSyntax)
 9652                    where symbol is not null
 9653                    let serviceContract = symbol
 9654                    where serviceContract.GetOneAttributeOf(_sSMServiceContractSymbol, _coreWCFServiceContractSymbol) is
 9655                    where !HasOpenGenericContext(serviceContract)
 7256                    where !serviceContract.IsPrivate()
 14057                    select serviceContract).ToImmutableArray();
 58
 28059                foreach (INamedTypeSymbol serviceContract in serviceContracts)
 60                {
 26461                    foreach (IMethodSymbol operationContract in GetOperationContracts(serviceContract))
 62                    {
 6863                        string operationKey = operationContract.ToDisplayString(s_methodDisplayFormat);
 6864                        if (emittedOperations.Add(operationKey))
 65                        {
 6066                            builder.Add(new OperationContractSpec(operationContract));
 67                        }
 68                    }
 69                }
 70
 7671                ImmutableArray<OperationContractSpec> operationContractSpecs = builder.ToImmutable();
 72
 7673                if (operationContractSpecs.IsEmpty)
 74                {
 2475                    return SourceGenerationSpec.None;
 76                }
 77
 5278                return new SourceGenerationSpec(operationContractSpecs);
 79            }
 80
 81        private IEnumerable<IMethodSymbol> GetOperationContracts(INamedTypeSymbol serviceContract)
 82        {
 30483            foreach (INamedTypeSymbol inheritedServiceContract in EnumerateServiceContracts(serviceContract))
 84            {
 32085                foreach (IMethodSymbol method in inheritedServiceContract.GetMembers().OfType<IMethodSymbol>())
 86                {
 7287                    if (method.GetOneAttributeOf(_sSMOperationContractSymbol, _coreWCFOperationContractSymbol) is null)
 88                    {
 89                        continue;
 90                    }
 91
 7292                    IMethodSymbol operationContract = serviceContract.FindImplementationForInterfaceMember(method) as IM
 7293                    if (HasOpenGenericContext(operationContract) || operationContract.IsPrivate())
 94                    {
 95                        continue;
 96                    }
 97
 6898                    yield return operationContract;
 99                }
 100            }
 64101        }
 102
 103        private IEnumerable<INamedTypeSymbol> EnumerateServiceContracts(INamedTypeSymbol serviceContract)
 104        {
 64105            yield return serviceContract;
 106
 176107            foreach (INamedTypeSymbol inheritedInterface in serviceContract.AllInterfaces)
 108            {
 24109                if (inheritedInterface.GetOneAttributeOf(_sSMServiceContractSymbol, _coreWCFServiceContractSymbol) is no
 110                {
 24111                    yield return inheritedInterface;
 112                }
 113            }
 64114        }
 115
 116        private static bool HasOpenGenericContext(IMethodSymbol method)
 117        {
 72118            if (method.TypeParameters.Length > 0)
 119            {
 4120                return true;
 121            }
 122
 68123            return HasOpenGenericContext(method.ContainingType);
 124        }
 125
 126        private static bool HasOpenGenericContext(INamedTypeSymbol? containingType)
 127        {
 460128            for (; containingType != null; containingType = containingType.ContainingType)
 129            {
 172130                if (IsOpenGenericType(containingType))
 131                {
 24132                    return true;
 133                }
 134            }
 135
 140136            return false;
 137        }
 138
 139        private static bool IsOpenGenericType(INamedTypeSymbol type)
 140        {
 172141            return type.IsGenericType && type.TypeArguments.Any(ContainsTypeParameter);
 142        }
 143
 144        private static bool ContainsTypeParameter(ITypeSymbol type)
 145        {
 64146            if (type.TypeKind == TypeKind.TypeParameter)
 147            {
 24148                return true;
 149            }
 150
 40151            if (type is IArrayTypeSymbol arrayType)
 152            {
 0153                return ContainsTypeParameter(arrayType.ElementType);
 154            }
 155
 40156            if (type is IPointerTypeSymbol pointerType)
 157            {
 0158                return ContainsTypeParameter(pointerType.PointedAtType);
 159            }
 160
 40161            return type is INamedTypeSymbol namedType
 40162                   && namedType.IsGenericType
 40163                   && namedType.TypeArguments.Any(ContainsTypeParameter);
 164        }
 165
 0166        internal static bool IsSyntaxTargetForGeneration(SyntaxNode node) => node is InterfaceDeclarationSyntax interfac
 0167                                                                             && interfaceDeclarationSyntax.AttributeList
 168
 169        internal static InterfaceDeclarationSyntax? GetSemanticTargetForGeneration(GeneratorSyntaxContext context)
 170        {
 0171                var interfaceDeclarationSyntax = (InterfaceDeclarationSyntax)context.Node;
 0172                foreach (var attributeList in interfaceDeclarationSyntax.AttributeLists)
 173                {
 0174                    foreach (var attribute in attributeList.Attributes)
 175                    {
 0176                        var attributeSymbol = context.SemanticModel.GetSymbolInfo(attribute).Symbol as IMethodSymbol;
 0177                        if (attributeSymbol == null)
 178                        {
 179                            continue;
 180                        }
 181
 0182                        var attributeContainingTypeSymbol = attributeSymbol.ContainingType;
 0183                        var fullName = attributeContainingTypeSymbol.ToDisplayString();
 184
 0185                        if (fullName == "CoreWCF.ServiceContractAttribute" || fullName == "System.ServiceModel.ServiceCo
 186                        {
 0187                            return interfaceDeclarationSyntax;
 188                        }
 189                    }
 190                }
 191
 0192                return null;
 193            }
 194    }
 195}

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.BuildTools/src/OperationInvokerGenerator.Roslyn4.0.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections.Immutable;
 5using Microsoft.CodeAnalysis;
 6using Microsoft.CodeAnalysis.CSharp.Syntax;
 7using Microsoft.CodeAnalysis.Text;
 8
 9namespace CoreWCF.BuildTools;
 10
 11[Generator(LanguageNames.CSharp)]
 12public sealed partial class OperationInvokerGenerator : IIncrementalGenerator
 13{
 14    public void Initialize(IncrementalGeneratorInitializationContext context)
 15    {
 8016        IncrementalValueProvider<bool> enabledProvider = context.AnalyzerConfigOptionsProvider
 8017            .Select(static (options, _) =>
 16018                options.GlobalOptions.TryGetValue("build_property.EnableCoreWCFOperationInvokerGenerator", out string? v
 16019                && val == "true");
 20
 8021        IncrementalValuesProvider<InterfaceDeclarationSyntax> coreWCFInterfaces = context.SyntaxProvider
 8022            .ForAttributeWithMetadataName(
 8023                "CoreWCF.ServiceContractAttribute",
 10024                predicate: static (node, _) => node is InterfaceDeclarationSyntax,
 13025                transform: static (ctx, _) => (InterfaceDeclarationSyntax)ctx.TargetNode);
 26
 8027        IncrementalValuesProvider<InterfaceDeclarationSyntax> ssmInterfaces = context.SyntaxProvider
 8028            .ForAttributeWithMetadataName(
 8029                "System.ServiceModel.ServiceContractAttribute",
 10030                predicate: static (node, _) => node is InterfaceDeclarationSyntax,
 13031                transform: static (ctx, _) => (InterfaceDeclarationSyntax)ctx.TargetNode);
 32
 8033        IncrementalValueProvider<ImmutableArray<InterfaceDeclarationSyntax>> interfaceDeclarations = coreWCFInterfaces.C
 8034            .Combine(ssmInterfaces.Collect())
 16035            .Select(static (pair, _) => pair.Left.AddRange(pair.Right));
 36
 8037        IncrementalValueProvider<(bool Enabled, (Compilation Compilation, ImmutableArray<InterfaceDeclarationSyntax> Int
 8038            enabledProvider.Combine(context.CompilationProvider.Combine(interfaceDeclarations));
 39
 8040        context.RegisterSourceOutput(compilationAndInterfaces, (spc, source)
 16041            => Execute(source.Enabled, source.CompilationAndInterfaces.Compilation, source.CompilationAndInterfaces.Inte
 8042    }
 43
 44    private void Execute(bool enabled, Compilation compilation, ImmutableArray<InterfaceDeclarationSyntax> contextInterf
 45    {
 8046        if (!enabled)
 47        {
 448            return;
 49        }
 50
 7651        if (contextInterfaces.IsDefaultOrEmpty)
 52        {
 053            return;
 54        }
 55
 7656        OperationInvokerSourceGenerationContext context = new(sourceProductionContext);
 7657        Parser parser = new(compilation, context);
 7658        SourceGenerationSpec spec = parser.GetGenerationSpec(contextInterfaces);
 7659        if (spec != SourceGenerationSpec.None)
 60        {
 5261            Emitter emitter = new(context, spec);
 5262            emitter.Emit();
 63        }
 7664    }
 65
 66    internal readonly struct OperationInvokerSourceGenerationContext
 67    {
 68        private readonly SourceProductionContext _context;
 69
 70        public OperationInvokerSourceGenerationContext(SourceProductionContext context)
 71        {
 7672                _context = context;
 7673            }
 74
 75        public void ReportDiagnostic(Diagnostic diagnostic)
 76        {
 077                _context.ReportDiagnostic(diagnostic);
 078            }
 79
 80        public void AddSource(string hintName, SourceText sourceText)
 81        {
 5282                _context.AddSource(hintName, sourceText);
 5283            }
 84    }
 85}

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.BuildTools/src/OperationInvokerGenerator.SourceGenerationSpec.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections.Immutable;
 5
 6namespace CoreWCF.BuildTools;
 7
 8public sealed partial class OperationInvokerGenerator
 9{
 10    internal readonly record struct SourceGenerationSpec(in ImmutableArray<OperationContractSpec> OperationContractSpecs
 11    {
 15612        public ImmutableArray<OperationContractSpec> OperationContractSpecs { get; } = OperationContractSpecs;
 13
 14        public static readonly SourceGenerationSpec None = new();
 15    }
 16}

Methods/Properties

.cctor()
.ctor(CoreWCF.BuildTools.OperationInvokerGenerator/OperationInvokerSourceGenerationContext&,CoreWCF.BuildTools.OperationInvokerGenerator/SourceGenerationSpec&)
Emit()
EmitOperationContract(CoreWCF.BuildTools.OperationInvokerGenerator/OperationContractSpec,System.Int32)
GetOperationInvokerTypeName(System.Int32)
EscapeIdentifier(System.String)
FlowsIn(Microsoft.CodeAnalysis.IParameterSymbol)
FlowOut(Microsoft.CodeAnalysis.IParameterSymbol)
GetRefKind(Microsoft.CodeAnalysis.IParameterSymbol)
Method()
.cctor()
.ctor(Microsoft.CodeAnalysis.Compilation,CoreWCF.BuildTools.OperationInvokerGenerator/OperationInvokerSourceGenerationContext&)
GetGenerationSpec(System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CSharp.Syntax.InterfaceDeclarationSyntax>)
GetOperationContracts()
EnumerateServiceContracts()
HasOpenGenericContext(Microsoft.CodeAnalysis.IMethodSymbol)
HasOpenGenericContext(Microsoft.CodeAnalysis.INamedTypeSymbol)
IsOpenGenericType(Microsoft.CodeAnalysis.INamedTypeSymbol)
ContainsTypeParameter(Microsoft.CodeAnalysis.ITypeSymbol)
IsSyntaxTargetForGeneration(Microsoft.CodeAnalysis.SyntaxNode)
GetSemanticTargetForGeneration(Microsoft.CodeAnalysis.GeneratorSyntaxContext)
Initialize(Microsoft.CodeAnalysis.IncrementalGeneratorInitializationContext)
Execute(System.Boolean,Microsoft.CodeAnalysis.Compilation,System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CSharp.Syntax.InterfaceDeclarationSyntax>,Microsoft.CodeAnalysis.SourceProductionContext)
.ctor(Microsoft.CodeAnalysis.SourceProductionContext)
ReportDiagnostic(Microsoft.CodeAnalysis.Diagnostic)
AddSource(System.String,Microsoft.CodeAnalysis.Text.SourceText)
OperationContractSpecs()