Exemplo n.º 1
0
 public RoslynAttributeInfo(AttributeData attributeData)
 {
     Attribute     = attributeData;
     AttributeType = RoslynTypeInfo.From(attributeData.AttributeClass);
     AttributeData = attributeData.NamedArguments
                     .Concat((attributeData.AttributeConstructor?.Parameters ?? (IEnumerable <IParameterSymbol>) new IParameterSymbol[0])
                             .Select(x => x.Name)
                             .Zip(attributeData.ConstructorArguments, (name, value) => new KeyValuePair <string, TypedConstant>(name, value)))
                     .ToDictionary(x => x.Key, x => GetValue(x.Value));
 }
 private static object?GetValue(TypedConstant argument)
 {
     if (argument.Kind == TypedConstantKind.Array)
     {
         return(argument.Values.Select(GetValue).ToArray());
     }
     if (argument.Value is ITypeSymbol typeSymbol)
     {
         return(RoslynTypeInfo.From(typeSymbol));
     }
     return(argument.Value);
 }
        public RoslynAttributeInfo(AttributeData attributeData)
        {
            if (attributeData.AttributeClass == null)
            {
                throw new InvalidOperationException($"Expected AttributeClass to be not null for AttributeData: {attributeData}");
            }

            Attribute     = attributeData;
            AttributeType = RoslynTypeInfo.From(attributeData.AttributeClass);
            AttributeData = attributeData.NamedArguments
                            .Concat((attributeData.AttributeConstructor?.Parameters ?? (IEnumerable <IParameterSymbol>) new IParameterSymbol[0])
                                    .Select(x => x.Name)
                                    .Zip(attributeData.ConstructorArguments, (name, value) => new KeyValuePair <string, TypedConstant>(name, value)))
                            .ToDictionary(x => x.Key, x => GetValue(x.Value));
        }
        public override SyntaxNode?VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var symbol = semanticModel.GetSymbolInfo(node).Symbol;

            if (symbol == null || !(symbol is IMethodSymbol methodSymbol))
            {
                return(base.VisitInvocationExpression(node));
            }

            if (methodSymbol.ContainingType?.ToString() != typeInfoName || methodSymbol.Name != methodName)
            {
                return(base.VisitInvocationExpression(node));
            }

            var foundType = GetSingleType(node.Expression, node.ArgumentList);

            Types.Add(RoslynTypeInfo.From(semanticModel.GetTypeInfo(foundType).Type));
            return(ArrayElement(Types.Count - 1));
        }