Exemplo n.º 1
0
        public override string VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            SymbolInfo exprSymbol = GetModel(node).GetSymbolInfo(node.Expression);

            if (exprSymbol.Symbol.Kind == SymbolKind.NamedType)
            {
                SymbolInfo symbolInfo = GetModel(node).GetSymbolInfo(node);
                ISymbol    symbol     = symbolInfo.Symbol;

                // Enum field
                INamedTypeSymbol namedTypeSymbol = (INamedTypeSymbol)exprSymbol.Symbol;
                if (namedTypeSymbol.TypeKind == TypeKind.Enum)
                {
                    IFieldSymbol enumFieldSymbol     = (IFieldSymbol)symbol;
                    string       constantValueString = enumFieldSymbol.ConstantValue.ToString();
                    if (namedTypeSymbol.EnumUnderlyingType.SpecialType == SpecialType.System_UInt32)
                    {
                        // TODO: We need to do this for literal values too, if they don't already have this suffix,
                        // so this should be refactored.
                        constantValueString += "u";
                    }
                    return(constantValueString);
                }

                // Static member access
                if (symbol.Kind == SymbolKind.Property || symbol.Kind == SymbolKind.Field)
                {
                    return(Visit(node.Name));
                }

                string typeName   = Utilities.GetFullMetadataName(exprSymbol.Symbol);
                string targetName = Visit(node.Name);
                return(_backend.FormatInvocation(_setName, typeName, targetName, Array.Empty <InvocationParameterInfo>()));
            }
            else
            {
                // Other accesses
                bool   isIndexerAccess = _backend.IsIndexerAccess(GetModel(node).GetSymbolInfo(node.Name));
                string expr            = Visit(node.Expression);
                string name            = Visit(node.Name);

                if (!isIndexerAccess)
                {
                    return(Visit(node.Expression)
                           + node.OperatorToken.ToFullString()
                           + Visit(node.Name));
                }
                else
                {
                    return(Visit(node.Expression)
                           + Visit(node.Name));
                }
            }
        }
Exemplo n.º 2
0
        public override string VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            if (node.Expression is IdentifierNameSyntax ins)
            {
                InvocationParameterInfo[] parameterInfos = GetParameterInfos(node.ArgumentList);
                SymbolInfo symbolInfo = GetModel(node).GetSymbolInfo(ins);
                string     type       = symbolInfo.Symbol.ContainingType.ToDisplayString();
                string     method     = symbolInfo.Symbol.Name;
                return(_backend.FormatInvocation(_setName, type, method, parameterInfos));
            }
            else if (node.Expression is MemberAccessExpressionSyntax maes)
            {
                SymbolInfo methodSymbol = GetModel(maes).GetSymbolInfo(maes);
                if (methodSymbol.Symbol is IMethodSymbol ims)
                {
                    string containingType = Utilities.GetFullMetadataName(ims.ContainingType);
                    string methodName     = ims.MetadataName;
                    List <InvocationParameterInfo> pis = new List <InvocationParameterInfo>();
                    if (ims.IsExtensionMethod)
                    {
                        string identifier = null;
                        // Extension method invocation, ie: swizzle:
                        if (maes.Expression is MemberAccessExpressionSyntax subExpression)
                        {
                            identifier = Visit(subExpression);
                        }
                        else if (maes.Expression is IdentifierNameSyntax identNameSyntax)
                        {
                            identifier = Visit(identNameSyntax);
                        }

                        Debug.Assert(identifier != null);
                        // Might need FullTypeName here too.
                        pis.Add(new InvocationParameterInfo()
                        {
                            Identifier = identifier
                        });
                    }

                    pis.AddRange(GetParameterInfos(node.ArgumentList));
                    return(_backend.FormatInvocation(_setName, containingType, methodName, pis.ToArray()));
                }

                throw new NotImplementedException();
            }
            else
            {
                string message = "Function calls must be made through an IdentifierNameSyntax or a MemberAccessExpressionSyntax.";
                message += Environment.NewLine + "This node used a " + node.Expression.GetType().Name;
                message += Environment.NewLine + node.ToFullString();
                throw new NotImplementedException(message);
            }
        }
Exemplo n.º 3
0
        public override string VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            SymbolInfo exprSymbol = GetModel(node).GetSymbolInfo(node.Expression);

            if (exprSymbol.Symbol.Kind == SymbolKind.NamedType)
            {
                // Static member access
                string typeName   = Utilities.GetFullMetadataName(exprSymbol.Symbol);
                string targetName = Visit(node.Name);
                return(_backend.FormatInvocation(_setName, typeName, targetName, Array.Empty <InvocationParameterInfo>()));
            }
            else
            {
                // Other accesses

                return(Visit(node.Expression)
                       + node.OperatorToken.ToFullString()
                       + Visit(node.Name));
            }
        }