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

106 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp;
internal sealed class WithPrimaryConstructorParametersBinder : Binder
{
private readonly NamedTypeSymbol _type;
private MethodSymbol? _lazyPrimaryCtorWithParameters = ErrorMethodSymbol.UnknownMethod;
private MultiDictionary<string, ParameterSymbol>? _lazyParameterMap;
internal WithPrimaryConstructorParametersBinder(NamedTypeSymbol type, Binder next)
: base(next)
{
_type = type;
}
internal override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
{
if (!options.CanConsiderMembers())
{
return;
}
EnsurePrimaryConstructor();
if ((object)_lazyPrimaryCtorWithParameters == null)
{
return;
}
ImmutableArray<ParameterSymbol>.Enumerator enumerator = _lazyPrimaryCtorWithParameters.Parameters.GetEnumerator();
while (enumerator.MoveNext())
{
ParameterSymbol current = enumerator.Current;
if (originalBinder.CanAddLookupSymbolInfo(current, options, result, null))
{
((AbstractLookupSymbolsInfo<Symbol>)result).AddSymbol((Symbol)current, current.Name, 0);
}
}
}
private void EnsurePrimaryConstructor()
{
if ((object)_lazyPrimaryCtorWithParameters != ErrorMethodSymbol.UnknownMethod)
{
return;
}
if (_type is SourceMemberContainerTypeSymbol sourceMemberContainerTypeSymbol)
{
SynthesizedPrimaryConstructor primaryConstructor = sourceMemberContainerTypeSymbol.PrimaryConstructor;
if ((object)primaryConstructor != null && primaryConstructor.ParameterCount != 0)
{
_lazyPrimaryCtorWithParameters = primaryConstructor;
return;
}
}
_lazyPrimaryCtorWithParameters = null;
}
internal override void LookupSymbolsInSingleBinder(LookupResult result, string name, int arity, ConsList<TypeSymbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
{
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//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)
if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly)) != LookupOptions.Default)
{
return;
}
EnsurePrimaryConstructor();
if ((object)_lazyPrimaryCtorWithParameters == null)
{
return;
}
MultiDictionary<string, ParameterSymbol> val = _lazyParameterMap;
if (val == null)
{
ImmutableArray<ParameterSymbol> parameters = _lazyPrimaryCtorWithParameters.Parameters;
val = new MultiDictionary<string, ParameterSymbol>(parameters.Length, (IEqualityComparer<string>)EqualityComparer<string>.Default, (IEqualityComparer<ParameterSymbol>)null);
ImmutableArray<ParameterSymbol>.Enumerator enumerator = parameters.GetEnumerator();
while (enumerator.MoveNext())
{
ParameterSymbol current = enumerator.Current;
val.Add(current.Name, current);
}
_lazyParameterMap = val;
}
Enumerator<string, ParameterSymbol> enumerator2 = val[name].GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
ParameterSymbol current2 = enumerator2.Current;
result.MergeEqual(originalBinder.CheckViability(current2, arity, options, null, diagnose, ref useSiteInfo));
}
}
finally
{
((IDisposable)enumerator2/*cast due to constrained. prefix*/).Dispose();
}
}
}