using System.Collections.Immutable; using System.Threading; using Microsoft.Cci; using Microsoft.CodeAnalysis.CSharp.Emit; using Microsoft.CodeAnalysis.CSharp.Emit.NoPia; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.Emit; namespace Microsoft.CodeAnalysis.CSharp; internal sealed class SynthesizedMetadataCompiler : CSharpSymbolVisitor { private readonly PEModuleBuilder _moduleBeingBuilt; private readonly CancellationToken _cancellationToken; private SynthesizedMetadataCompiler(PEModuleBuilder moduleBeingBuilt, CancellationToken cancellationToken) { _moduleBeingBuilt = moduleBeingBuilt; _cancellationToken = cancellationToken; } public static void ProcessSynthesizedMembers(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuilt, CancellationToken cancellationToken) { new SynthesizedMetadataCompiler(moduleBeingBuilt, cancellationToken).Visit(compilation.SourceModule.GlobalNamespace); } public override void VisitNamespace(NamespaceSymbol symbol) { CancellationToken cancellationToken = _cancellationToken; cancellationToken.ThrowIfCancellationRequested(); ImmutableArray.Enumerator enumerator = symbol.GetMembers().GetEnumerator(); while (enumerator.MoveNext()) { enumerator.Current.Accept(this); } } public override void VisitNamedType(NamedTypeSymbol symbol) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Invalid comparison between Unknown and I4 //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Invalid comparison between Unknown and I4 CancellationToken cancellationToken = _cancellationToken; cancellationToken.ThrowIfCancellationRequested(); if (symbol is SourceMemberContainerTypeSymbol sourceMemberContainerTypeSymbol && _moduleBeingBuilt != null) { ImmutableArray.Enumerator enumerator = sourceMemberContainerTypeSymbol.GetSynthesizedExplicitImplementations(_cancellationToken).ForwardingMethods.GetEnumerator(); while (enumerator.MoveNext()) { SynthesizedExplicitImplementationForwardingMethod current = enumerator.Current; ((PEModuleBuilder)_moduleBeingBuilt).AddSynthesizedDefinition(symbol, (IMethodDefinition)(object)current.GetCciAdapter()); } } ImmutableArray.Enumerator enumerator2 = symbol.GetMembers().GetEnumerator(); while (enumerator2.MoveNext()) { Symbol current2 = enumerator2.Current; SymbolKind kind = current2.Kind; if ((int)kind == 11 || (int)kind == 15) { current2.Accept(this); } } } public override void VisitProperty(PropertySymbol symbol) { if (symbol is SourcePropertySymbolBase { IsSealed: not false, SynthesizedSealedAccessorOpt: { } synthesizedSealedAccessorOpt } sourcePropertySymbolBase) { ((PEModuleBuilder)_moduleBeingBuilt).AddSynthesizedDefinition(sourcePropertySymbolBase.ContainingType, (IMethodDefinition)(object)synthesizedSealedAccessorOpt.GetCciAdapter()); } } }