public override void Resolve(SyntaxTreeNode_Leaf leaf, int numTypeArgs, bool asTypeOnly)
    {
        if (declaration != null && declaration.definition != null)
        {
            declaration.definition.ResolveMember(leaf, this, numTypeArgs, asTypeOnly);

            if (numTypeArgs == 0 && leaf.ResolvedSymbol == null)
            {
                var typeParams = declaration.definition.GetTypeParameters();
                if (typeParams != null)
                {
                    var id = SymbolDefinition.DecodeId(leaf.token.text);
                    for (int i = typeParams.Count; i-- > 0;)
                    {
                        if (typeParams[i].GetName() == id)
                        {
                            leaf.ResolvedSymbol = typeParams[i];
                            break;
                        }
                    }
                }
            }
        }

        if (leaf.ResolvedSymbol == null)
        {
            base.Resolve(leaf, numTypeArgs, asTypeOnly);
        }
    }
    public override void Resolve(SyntaxTreeNode_Leaf leaf, int numTypeArgs, bool asTypeOnly)
    {
        leaf.ResolvedSymbol = null;

        var id = SymbolDefinition.DecodeId(leaf.token.text);

        for (int i = declaration.typeAliases.Count; i-- > 0;)
        {
            if (declaration.typeAliases[i].name == id)
            {
                if (declaration.typeAliases[i].type != null)
                {
                    leaf.ResolvedSymbol = declaration.typeAliases[i].type.Definition;
                    return;
                }
                else
                {
                    break;
                }
            }
        }

        if (leaf.ResolvedSymbol == null)
        {
            for (var i = declaration.importedNamespaces.Count; i-- > 0;)
            {
                var nsRef = declaration.importedNamespaces[i];
                if (nsRef.IsBefore(leaf) && nsRef.Definition != null)
                {
                    nsRef.Definition.ResolveMember(leaf, this, numTypeArgs, true);
                    if (leaf.ResolvedSymbol != null)
                    {
                        if (leaf.ResolvedSymbol.kind == SymbolKind.Namespace)
                        {
                            leaf.ResolvedSymbol = null;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }

        var parentScopeDef = parentScope != null ? ((Scope_Namespace)parentScope).definition : null;

        for (var nsDef = definition;
             leaf.ResolvedSymbol == null && nsDef != null && nsDef != parentScopeDef;
             nsDef = nsDef.parentSymbol as SD_NameSpace)
        {
            nsDef.ResolveMember(leaf, this, numTypeArgs, true);
        }

        if (leaf.ResolvedSymbol == null && parentScope != null)
        {
            parentScope.Resolve(leaf, numTypeArgs, true);
        }
    }
    public override SymbolDefinition FindName(string symbolName, int numTypeParameters)
    {
        symbolName = SymbolDefinition.DecodeId(symbolName);

        if (numTypeParameters == 0 && localSymbols != null)
        {
            for (var i = localSymbols.Count; i-- > 0;)
            {
                if (localSymbols[i].name == symbolName)
                {
                    return(localSymbols[i]);
                }
            }
        }
        return(null);
    }
    public override void Resolve(SyntaxTreeNode_Leaf leaf, int numTypeArgs, bool asTypeOnly)
    {
        leaf.ResolvedSymbol = null;

        if (!asTypeOnly && localSymbols != null)
        {
            var id = SymbolDefinition.DecodeId(leaf.token.text);
            for (var i = localSymbols.Count; i-- > 0;)
            {
                if (localSymbols[i].name == id)
                {
                    leaf.ResolvedSymbol = localSymbols[i];
                    return;
                }
            }
        }

        base.Resolve(leaf, numTypeArgs, asTypeOnly);
    }
    public override SymbolDefinition ResolveAsExtensionMethod(SyntaxTreeNode_Leaf invokedLeaf, SymbolDefinition invokedSymbol, TypeDefinitionBase memberOf, SyntaxTreeNode_Rule argumentListNode, SymbolReference[] typeArgs, Scope_Base context)
    {
        if (invokedLeaf == null && (invokedSymbol == null || invokedSymbol.kind == SymbolKind.Error))
        {
            return(null);
        }

        var id = invokedSymbol != null && invokedSymbol.kind != SymbolKind.Error ? invokedSymbol.name : invokedLeaf != null?SymbolDefinition.DecodeId(invokedLeaf.token.text) : "";

        int numArguments = 1;

        Modifiers[] modifiers = null;
        List <TypeDefinitionBase> argumentTypes = null;

        MethodDefinition firstAccessibleMethod = null;

        var thisAssembly = GetAssembly();

        var extensionsMethods = new HashSet <MethodDefinition>();

        thisAssembly.CollectExtensionMethods(definition, id, typeArgs, memberOf, extensionsMethods, context);
        if (extensionsMethods.Count > 0)
        {
            firstAccessibleMethod = extensionsMethods.First();

            if (argumentTypes == null)
            {
                numArguments = SD_MethodGroup.ProcessArgumentListNode(argumentListNode, out modifiers, out argumentTypes, memberOf);
            }

            var candidates = new List <MethodDefinition>(extensionsMethods.Count);
            foreach (var method in extensionsMethods)
            {
                if (argumentTypes == null || method.CanCallWith(modifiers, true))
                {
                    candidates.Add(method);
                }
            }

            if (typeArgs == null)
            {
                for (var i = candidates.Count; i-- > 0;)
                {
                    var candidate = candidates[i];
                    if (candidate.NumTypeParameters == 0 || argumentTypes == null)
                    {
                        continue;
                    }

                    candidate = SD_MethodGroup.InferMethodTypeArguments(candidate, argumentTypes, invokedLeaf);
                    if (candidate == null)
                    {
                        candidates.RemoveAt(i);
                    }
                    else
                    {
                        candidates[i] = candidate;
                    }
                }
            }

            var resolved = SD_MethodGroup.ResolveMethodOverloads(numArguments, argumentTypes, modifiers, candidates);
            if (resolved != null && resolved.kind != SymbolKind.Error)
            {
                return(resolved);
            }
        }

        extensionsMethods.Clear();

        var importedNamespaces = declaration.importedNamespaces;

        for (var i = importedNamespaces.Count; i-- > 0;)
        {
            var nsDef = importedNamespaces[i].Definition as SD_NameSpace;
            if (nsDef != null)
            {
                thisAssembly.CollectExtensionMethods(nsDef, id, typeArgs, memberOf, extensionsMethods, context);
            }
        }
        if (extensionsMethods.Count > 0)
        {
            if (firstAccessibleMethod == null)
            {
                firstAccessibleMethod = extensionsMethods.First();
            }

            if (argumentTypes == null)
            {
                numArguments = SD_MethodGroup.ProcessArgumentListNode(argumentListNode, out modifiers, out argumentTypes, memberOf);
            }

            var candidates = new List <MethodDefinition>(extensionsMethods.Count);
            foreach (var method in extensionsMethods)
            {
                if (argumentTypes == null || method.CanCallWith(modifiers, true))
                {
                    candidates.Add(method);
                }
            }

            if (typeArgs == null)
            {
                for (var i = candidates.Count; i-- > 0;)
                {
                    var candidate = candidates[i];
                    if (candidate.NumTypeParameters == 0 || argumentTypes == null)
                    {
                        continue;
                    }

                    candidate = SD_MethodGroup.InferMethodTypeArguments(candidate, argumentTypes, invokedLeaf);
                    if (candidate == null)
                    {
                        candidates.RemoveAt(i);
                    }
                    else
                    {
                        candidates[i] = candidate;
                    }
                }
            }

            var resolved = SD_MethodGroup.ResolveMethodOverloads(numArguments, argumentTypes, modifiers, candidates);
            if (resolved != null && resolved.kind != SymbolKind.Error)
            {
                return(resolved);
            }
        }

        if (parentScope != null)
        {
            var resolved = parentScope.ResolveAsExtensionMethod(invokedLeaf, invokedSymbol, memberOf, argumentListNode, typeArgs, context);
            if (resolved != null)
            {
                return(resolved);
            }
        }

        if (firstAccessibleMethod != null)
        {
            invokedLeaf.ResolvedSymbol   = firstAccessibleMethod;
            invokedLeaf.m_sSemanticError = SD_MethodGroup.unresolvedMethodOverload.name;
        }
        return(null);
    }