31 lines
1.6 KiB
C#
31 lines
1.6 KiB
C#
using System.Collections.Immutable;
|
|
using Microsoft.CodeAnalysis.CodeGen;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal sealed class SynthesizedThrowSwitchExpressionExceptionMethod : SynthesizedGlobalMethodSymbol
|
|
{
|
|
internal SynthesizedThrowSwitchExpressionExceptionMethod(SourceModuleSymbol containingModule, PrivateImplementationDetails privateImplType, TypeSymbol returnType, TypeSymbol paramType)
|
|
: base(containingModule, privateImplType, returnType, "ThrowSwitchExpressionException")
|
|
{
|
|
SetParameters(ImmutableArray.Create(SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(paramType), 0, (RefKind)0, "unmatchedValue", (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
|
|
{
|
|
ParameterSymbol p = Parameters[0];
|
|
BoundThrowStatement body = syntheticBoundNodeFactory.Throw(syntheticBoundNodeFactory.New(syntheticBoundNodeFactory.WellKnownMethod((WellKnownMember)456), ImmutableArray.Create((BoundExpression)syntheticBoundNodeFactory.Parameter(p))));
|
|
syntheticBoundNodeFactory.CloseMethod(body);
|
|
}
|
|
catch (SyntheticBoundNodeFactory.MissingPredefinedMember missingPredefinedMember)
|
|
{
|
|
((BindingDiagnosticBag)diagnostics).Add(missingPredefinedMember.Diagnostic);
|
|
syntheticBoundNodeFactory.CloseMethod(syntheticBoundNodeFactory.ThrowNull());
|
|
}
|
|
}
|
|
}
|