<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />

CMemberLookupResults

using Microsoft.CSharp.RuntimeBinder.Syntax; namespace Microsoft.CSharp.RuntimeBinder.Semantics { internal class CMemberLookupResults { public class CMethodIterator { private SymbolLoader _pSymbolLoader; private CSemanticChecker _pSemanticChecker; private AggregateType _pCurrentType; private MethodOrPropertySymbol _pCurrentSym; private Declaration _pContext; private TypeArray _pContainingTypes; private CType _pQualifyingType; private Name _pName; private int _nArity; private symbmask_t _mask; private EXPRFLAG _flags; private int _nCurrentTypeCount; private bool _bIsCheckingInstanceMethods; private bool _bAtEnd; private bool _bAllowBogusAndInaccessible; private bool _bAllowExtensionMethods; private bool _bCurrentSymIsBogus; private bool _bCurrentSymIsInaccessible; private bool _bcanIncludeExtensionsInResults; private bool _bEndIterationAtCurrentExtensionList; public CMethodIterator(CSemanticChecker checker, SymbolLoader symLoader, Name name, TypeArray containingTypes, CType object, CType qualifyingType, Declaration context, bool allowBogusAndInaccessible, bool allowExtensionMethods, int arity, EXPRFLAG flags, symbmask_t mask) { _pSemanticChecker = checker; _pSymbolLoader = symLoader; _pCurrentType = null; _pCurrentSym = null; _pName = name; _pContainingTypes = containingTypes; _pQualifyingType = qualifyingType; _pContext = context; _bAllowBogusAndInaccessible = allowBogusAndInaccessible; _bAllowExtensionMethods = allowExtensionMethods; _nArity = arity; _flags = flags; _mask = mask; _nCurrentTypeCount = 0; _bIsCheckingInstanceMethods = true; _bAtEnd = false; _bCurrentSymIsBogus = false; _bCurrentSymIsInaccessible = false; _bcanIncludeExtensionsInResults = _bAllowExtensionMethods; _bEndIterationAtCurrentExtensionList = false; } public MethodOrPropertySymbol GetCurrentSymbol() { return _pCurrentSym; } public AggregateType GetCurrentType() { return _pCurrentType; } public bool IsCurrentSymbolInaccessible() { return _bCurrentSymIsInaccessible; } public bool IsCurrentSymbolBogus() { return _bCurrentSymIsBogus; } public bool MoveNext(bool canIncludeExtensionsInResults, bool endatCurrentExtensionList) { if (_bcanIncludeExtensionsInResults) _bcanIncludeExtensionsInResults = canIncludeExtensionsInResults; if (!_bEndIterationAtCurrentExtensionList) _bEndIterationAtCurrentExtensionList = endatCurrentExtensionList; if (_bAtEnd) return false; if (_pCurrentType == null) { if (_pContainingTypes.size == 0) { _bIsCheckingInstanceMethods = false; _bAtEnd = true; return false; } if (!FindNextTypeForInstanceMethods()) { _bAtEnd = true; return false; } } if (!FindNextMethod()) { _bAtEnd = true; return false; } return true; } public bool AtEnd() { return _pCurrentSym == null; } private CSemanticChecker GetSemanticChecker() { return _pSemanticChecker; } private SymbolLoader GetSymbolLoader() { return _pSymbolLoader; } public bool CanUseCurrentSymbol() { _bCurrentSymIsInaccessible = false; _bCurrentSymIsBogus = false; if ((_mask == symbmask_t.MASK_MethodSymbol && ((_flags & EXPRFLAG.EXF_CTOR) == (EXPRFLAG)0 != !_pCurrentSym.AsMethodSymbol().IsConstructor() || (_flags & EXPRFLAG.EXF_OPERATOR) == (EXPRFLAG)0 != !_pCurrentSym.AsMethodSymbol().isOperator)) || (_mask == symbmask_t.MASK_PropertySymbol && !_pCurrentSym.AsPropertySymbol().isIndexer())) return false; if (_nArity > 0 && _mask == symbmask_t.MASK_MethodSymbol && _pCurrentSym.AsMethodSymbol().typeVars.size != _nArity) return false; if (!ExpressionBinder.IsMethPropCallable(_pCurrentSym, (_flags & EXPRFLAG.EXF_USERCALLABLE) != (EXPRFLAG)0)) return false; if (!GetSemanticChecker().CheckAccess(_pCurrentSym, _pCurrentType, _pContext, _pQualifyingType)) { if (!_bAllowBogusAndInaccessible) return false; _bCurrentSymIsInaccessible = true; } if (GetSemanticChecker().CheckBogus(_pCurrentSym)) { if (!_bAllowBogusAndInaccessible) return false; _bCurrentSymIsBogus = true; } if (!_bIsCheckingInstanceMethods && !_pCurrentSym.AsMethodSymbol().IsExtension()) return false; return true; } private bool FindNextMethod() { while (true) { if (_pCurrentSym == null) _pCurrentSym = GetSymbolLoader().LookupAggMember(_pName, _pCurrentType.getAggregate(), _mask).AsMethodOrPropertySymbol(); else _pCurrentSym = GetSymbolLoader().LookupNextSym(_pCurrentSym, _pCurrentType.getAggregate(), _mask).AsMethodOrPropertySymbol(); if (_pCurrentSym != null) break; if (_bIsCheckingInstanceMethods) { if (!FindNextTypeForInstanceMethods() && _bcanIncludeExtensionsInResults) _bIsCheckingInstanceMethods = false; else if (_pCurrentType == null && !_bcanIncludeExtensionsInResults) { return false; } } } return true; } private bool FindNextTypeForInstanceMethods() { if (_pContainingTypes.size > 0) { if (_nCurrentTypeCount >= _pContainingTypes.size) _pCurrentType = null; else _pCurrentType = _pContainingTypes.Item(_nCurrentTypeCount++).AsAggregateType(); } else _pCurrentType = _pCurrentType.GetBaseClass(); return _pCurrentType != null; } } private Name _pName; public TypeArray ContainingTypes { get; set; } public CMemberLookupResults() { _pName = null; ContainingTypes = null; } public CMemberLookupResults(TypeArray containingTypes, Name name) { _pName = name; ContainingTypes = containingTypes; if (ContainingTypes == null) ContainingTypes = BSYMMGR.EmptyTypeArray(); } public CMethodIterator GetMethodIterator(CSemanticChecker pChecker, SymbolLoader pSymLoader, CType pObject, CType pQualifyingType, Declaration pContext, bool allowBogusAndInaccessible, bool allowExtensionMethods, int arity, EXPRFLAG flags, symbmask_t mask) { return new CMethodIterator(pChecker, pSymLoader, _pName, ContainingTypes, pObject, pQualifyingType, pContext, allowBogusAndInaccessible, allowExtensionMethods, arity, flags, mask); } } }