Files
2026-08-27 10:56:38 -06:00

34 lines
2.0 KiB
C#

using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CodeGen;
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
internal sealed class SynthesizedInlineArrayFirstElementRefReadOnlyMethod : SynthesizedGlobalMethodSymbol
{
public override RefKind RefKind => (RefKind)3;
internal SynthesizedInlineArrayFirstElementRefReadOnlyMethod(SourceModuleSymbol containingModule, PrivateImplementationDetails privateImplType, string synthesizedMethodName)
: base(containingModule, privateImplType, synthesizedMethodName)
{
SetTypeParameters(ImmutableArray.Create((TypeParameterSymbol)new SynthesizedSimpleMethodTypeParameterSymbol(this, 0, "TBuffer"), (TypeParameterSymbol)new SynthesizedSimpleMethodTypeParameterSymbol(this, 1, "TElement")));
SetReturnType(TypeParameters[1]);
SetParameters(ImmutableArray.Create(SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(TypeParameters[0]), 0, (RefKind)3, "buffer", (ScopedKind)0)));
}
internal override void GenerateMethodBody(TypeCompilationState compilationState, BindingDiagnosticBag diagnostics)
{
SyntheticBoundNodeFactory syntheticBoundNodeFactory = new SyntheticBoundNodeFactory(this, (SyntaxNode)(object)this.GetNonNullSyntaxNode(), compilationState, diagnostics);
syntheticBoundNodeFactory.CurrentFunction = this;
try
{
BoundReturnStatement body = syntheticBoundNodeFactory.Return(syntheticBoundNodeFactory.Call(null, syntheticBoundNodeFactory.WellKnownMethod((WellKnownMember)130).Construct(ImmutableArray<TypeSymbol>.CastUp(TypeParameters)), syntheticBoundNodeFactory.Call(null, syntheticBoundNodeFactory.WellKnownMethod((WellKnownMember)131).Construct(TypeParameters[0]), syntheticBoundNodeFactory.Parameter(Parameters[0]))));
syntheticBoundNodeFactory.CloseMethod(body);
}
catch (SyntheticBoundNodeFactory.MissingPredefinedMember missingPredefinedMember)
{
((BindingDiagnosticBag)diagnostics).Add(missingPredefinedMember.Diagnostic);
syntheticBoundNodeFactory.CloseMethod(syntheticBoundNodeFactory.ThrowNull());
}
}
}