當前位置: 首頁>>代碼示例>>C#>>正文


C# Syntax.SimpleNameSyntax類代碼示例

本文整理匯總了C#中Microsoft.CodeAnalysis.CSharp.Syntax.SimpleNameSyntax的典型用法代碼示例。如果您正苦於以下問題:C# SimpleNameSyntax類的具體用法?C# SimpleNameSyntax怎麽用?C# SimpleNameSyntax使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SimpleNameSyntax類屬於Microsoft.CodeAnalysis.CSharp.Syntax命名空間,在下文中一共展示了SimpleNameSyntax類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateInvocationExpression

 public static InvocationExpressionSyntax CreateInvocationExpression(ExpressionSyntax sourceExpression, SimpleNameSyntax methodName, ArgumentListSyntax argumentList) =>
     SyntaxFactory.InvocationExpression(
         SyntaxFactory.MemberAccessExpression(
         SyntaxKind.SimpleMemberAccessExpression,
         sourceExpression,
         methodName),
         argumentList);
開發者ID:JeanLLopes,項目名稱:code-cracker,代碼行數:7,代碼來源:CallExtensionMethodAsExtensionCodeFixProvider.cs

示例2: BindRangeVariable

            protected override BoundExpression BindRangeVariable(SimpleNameSyntax node, RangeVariableSymbol qv, DiagnosticBag diagnostics)
            {
                Debug.Assert(!qv.IsTransparent);

                BoundExpression translation;
                ImmutableArray<string> path;
                if (_rangeVariableMap.TryGetValue(qv, out path))
                {
                    if (path.IsEmpty)
                    {
                        // the range variable maps directly to a use of the parameter of that name
                        var value = base.parameterMap[qv.Name];
                        Debug.Assert(value.Count == 1);
                        translation = new BoundParameter(node, value.Single()) { WasCompilerGenerated = true };
                    }
                    else
                    {
                        // if the query variable map for this variable is non empty, we always start with the current
                        // lambda's first parameter, which is a transparent identifier.
                        Debug.Assert(base.lambdaSymbol.Parameters[0].Name.StartsWith(transparentIdentifierPrefix));
                        translation = new BoundParameter(node, base.lambdaSymbol.Parameters[0]) { WasCompilerGenerated = true };
                        for (int i = path.Length - 1; i >= 0; i--)
                        {
                            var nextField = path[i];
                            translation = SelectField(node, translation, nextField, diagnostics);
                            translation.WasCompilerGenerated = true;
                        }
                    }

                    return new BoundRangeVariable(node, qv, translation, translation.Type);
                }

                return base.BindRangeVariable(node, qv, diagnostics);
            }
開發者ID:elemk0vv,項目名稱:roslyn-1,代碼行數:34,代碼來源:Binder.WithQueryLambdaParametersBinder.cs

示例3: SelectField

            private BoundExpression SelectField(SimpleNameSyntax node, BoundExpression receiver, string name, DiagnosticBag diagnostics)
            {
                var receiverType = receiver.Type as NamedTypeSymbol;
                if ((object)receiverType == null || !receiverType.IsAnonymousType)
                {
                    // We only construct transparent query variables using anonymous types, so if we're trying to navigate through
                    // some other type, we must have some hinky query API where the types don't match up as expected.
                    // We should report this as an error of some sort.
                    // TODO: DevDiv #737822 - reword error message and add test.
                    var info = new CSDiagnosticInfo(ErrorCode.ERR_UnsupportedTransparentIdentifierAccess, name, receiver.ExpressionSymbol ?? receiverType);
                    Error(diagnostics, info, node);
                    return new BoundBadExpression(
                        node,
                        LookupResultKind.Empty,
                        ImmutableArray.Create<Symbol>(receiver.ExpressionSymbol),
                        ImmutableArray.Create<BoundNode>(receiver),
                        new ExtendedErrorTypeSymbol(this.Compilation, "", 0, info));
                }

                LookupResult lookupResult = LookupResult.GetInstance();
                LookupOptions options = LookupOptions.MustBeInstance;
                HashSet<DiagnosticInfo> useSiteDiagnostics = null;
                LookupMembersWithFallback(lookupResult, receiver.Type, name, 0, ref useSiteDiagnostics, basesBeingResolved: null, options: options);
                diagnostics.Add(node, useSiteDiagnostics);

                var result = BindMemberOfType(node, node, name, 0, receiver, default(SeparatedSyntaxList<TypeSyntax>), default(ImmutableArray<TypeSymbol>), lookupResult, BoundMethodGroupFlags.None, diagnostics);
                result.WasCompilerGenerated = true;
                lookupResult.Free();
                return result;
            }
開發者ID:elemk0vv,項目名稱:roslyn-1,代碼行數:30,代碼來源:Binder.WithQueryLambdaParametersBinder.cs

示例4: GetCallerMethodSymbol

 private static IMethodSymbol GetCallerMethodSymbol(SemanticModel semanticModel, SimpleNameSyntax name, int argumentsCount)
 {
     var symbolInfo = semanticModel.GetSymbolInfo(name);
     return symbolInfo.Symbol as IMethodSymbol ??
             symbolInfo
                 .CandidateSymbols
                 .OfType<IMethodSymbol>()
                 .FirstOrDefault(s => s.Parameters.Length == argumentsCount + 1);
 }
開發者ID:rsaladrigas,項目名稱:code-cracker,代碼行數:9,代碼來源:CallExtensionMethodAsExtensionAnalyzer.cs

示例5: OtherMethodExists

 private static bool OtherMethodExists(InvocationExpressionSyntax invocation, SimpleNameSyntax nameToCheck, SemanticModel semanticModel)
 {
     var otherExpression = ((MemberAccessExpressionSyntax)invocation.Expression).WithName(nameToCheck).WithAdditionalAnnotations(speculativeAnnotation);
     var statement = invocation.FirstAncestorOrSelfThatIsAStatement();
     var otherStatement = statement.ReplaceNode(invocation.Expression, otherExpression);
     SemanticModel speculativeModel;
     if (!semanticModel.TryGetSpeculativeSemanticModel(statement.SpanStart, otherStatement, out speculativeModel)) return false;
     var otherInvocationSymbol = speculativeModel.GetSymbolInfo(speculativeModel.SyntaxTree.GetRoot().GetAnnotatedNodes(speculativeAnnotationDescription).First());
     return otherInvocationSymbol.Symbol != null;
 }
開發者ID:transformersprimeabcxyz,項目名稱:code-cracker,代碼行數:10,代碼來源:ChangeAnyToAllAnalyzer.cs

示例6: IsReference

            private bool IsReference(SimpleNameSyntax name)
            {
                if (name.Identifier.ValueText != _variableDeclarator.Identifier.ValueText)
                {
                    return false;
                }

                var symbol = _semanticModel.GetSymbolInfo(name).Symbol;
                return symbol != null
                    && symbol.Equals(_localSymbol);
            }
開發者ID:CAPCHIK,項目名稱:roslyn,代碼行數:11,代碼來源:InlineTemporaryCodeRefactoringProvider.ReferenceRewriter.cs

示例7: GetTransformedDocumentAsync

        private static Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, SimpleNameSyntax node)
        {
            var qualifiedExpression =
                SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, ThisExpressionSyntax, node.WithoutTrivia().WithoutFormatting())
                .WithTriviaFrom(node)
                .WithoutFormatting();

            var newSyntaxRoot = root.ReplaceNode(node, qualifiedExpression);

            return Task.FromResult(document.WithSyntaxRoot(newSyntaxRoot));
        }
開發者ID:JaRau,項目名稱:StyleCopAnalyzers,代碼行數:11,代碼來源:SA1101CodeFixProvider.cs

示例8: From

 public static TypeNameText From(SimpleNameSyntax syntax)
 {
     var identifier = syntax.Identifier.Text;
     var typeArgs = string.Empty;
     var genericName = syntax as GenericNameSyntax;
     if (genericName != null && genericName.TypeArgumentList != null)
     {
         var count = genericName.TypeArgumentList.Arguments.Count;
         identifier = $"\"{identifier}`{count}\"";
         typeArgs = "<" + string.Join(",", genericName.TypeArgumentList.Arguments) + ">";
     }
     return new TypeNameText
     {
         Identifier = identifier,
         TypeArguments = typeArgs
     };
 }
開發者ID:pierre3,項目名稱:PlantUmlClassDiagramGenerator,代碼行數:17,代碼來源:TypeNameText.cs

示例9: IsSelectingADifferentMethod

 private static bool IsSelectingADifferentMethod(IEnumerable<SyntaxNode> childNodes, SimpleNameSyntax methodName, SyntaxTree tree, IMethodSymbol methodSymbol, ExpressionSyntax invocationExpression, Compilation compilation)
 {
     var parameterExpressions = GetParameterExpressions(childNodes);
     var firstArgument = parameterExpressions.FirstOrDefault();
     var argumentList = CreateArgumentListSyntaxFrom(parameterExpressions.Skip(1));
     var newInvocationStatement = CreateInvocationExpression(firstArgument, methodName, argumentList)
         .WithAdditionalAnnotations(introduceExtensionMethodAnnotation);
     var extensionMethodNamespaceUsingDirective = SyntaxFactory.UsingDirective(methodSymbol.ContainingNamespace.ToNameSyntax());
     var speculativeRootWithExtensionMethod = tree.GetCompilationUnitRoot()
         .ReplaceNode(invocationExpression, newInvocationStatement)
         .AddUsings(extensionMethodNamespaceUsingDirective);
     var speculativeModel = compilation.ReplaceSyntaxTree(tree, speculativeRootWithExtensionMethod.SyntaxTree)
         .GetSemanticModel(speculativeRootWithExtensionMethod.SyntaxTree);
     var speculativeInvocationStatement = speculativeRootWithExtensionMethod.SyntaxTree.GetCompilationUnitRoot().GetAnnotatedNodes(introduceExtensionMethodAnnotation).Single() as InvocationExpressionSyntax;
     var speculativeExtensionMethodSymbol = speculativeModel.GetSymbolInfo(speculativeInvocationStatement.Expression).Symbol as IMethodSymbol;
     var speculativeNonExtensionFormOfTheMethodSymbol = speculativeExtensionMethodSymbol?.GetConstructedReducedFrom();
     return speculativeNonExtensionFormOfTheMethodSymbol == null || !speculativeNonExtensionFormOfTheMethodSymbol.Equals(methodSymbol);
 }
開發者ID:haroldhues,項目名稱:code-cracker,代碼行數:18,代碼來源:CallExtensionMethodAsExtensionAnalyzer.cs

示例10: IsSelectingADifferentMethod

 private static bool IsSelectingADifferentMethod(IEnumerable<SyntaxNode> childNodes, SimpleNameSyntax methodName, SyntaxTree tree, IMethodSymbol methodSymbol, ExpressionSyntax invocationExpression, Compilation compilation)
 {
     var parameterExpressions = GetParameterExpressions(childNodes);
     var firstArgument = parameterExpressions.FirstOrDefault();
     var argumentList = CreateArgumentListSyntaxFrom(parameterExpressions.Skip(1));
     var newInvocationStatement = CreateInvocationExpression(firstArgument, methodName, argumentList)
         .WithAdditionalAnnotations(introduceExtensionMethodAnnotation);
     var extensionMethodNamespaceUsingDirective = SyntaxFactory.UsingDirective(methodSymbol.ContainingNamespace.ToNameSyntax());
     var speculativeRootWithExtensionMethod = tree.GetCompilationUnitRoot()
         .ReplaceNode(invocationExpression, newInvocationStatement)
         .AddUsings(extensionMethodNamespaceUsingDirective);
     var speculativeTree = speculativeRootWithExtensionMethod.SyntaxTree;
     var speculativeTreeOptions = (CSharpParseOptions)speculativeTree.Options;
     var speculativeTreeWithCorrectLanguageVersion = speculativeTree.WithRootAndOptions(speculativeRootWithExtensionMethod, speculativeTreeOptions.WithLanguageVersion(((CSharpParseOptions)tree.Options).LanguageVersion));
     var speculativeModel = compilation.ReplaceSyntaxTree(tree, speculativeTreeWithCorrectLanguageVersion)
         .GetSemanticModel(speculativeTreeWithCorrectLanguageVersion);
     var speculativeInvocationStatement = speculativeTreeWithCorrectLanguageVersion.GetCompilationUnitRoot().GetAnnotatedNodes(introduceExtensionMethodAnnotation).Single() as InvocationExpressionSyntax;
     var speculativeExtensionMethodSymbol = speculativeModel.GetSymbolInfo(speculativeInvocationStatement.Expression).Symbol as IMethodSymbol;
     var speculativeNonExtensionFormOfTheMethodSymbol = speculativeExtensionMethodSymbol?.GetConstructedReducedFrom();
     return speculativeNonExtensionFormOfTheMethodSymbol == null || speculativeNonExtensionFormOfTheMethodSymbol.ToString() != methodSymbol.ToString();//can't compare equality, as speculative symbol might be different
 }
開發者ID:julianosaless,項目名稱:code-cracker,代碼行數:21,代碼來源:CallExtensionMethodAsExtensionAnalyzer.cs

示例11: IsInvocationWithDynamicArguments

            private bool IsInvocationWithDynamicArguments(SimpleNameSyntax originalSimpleName, SemanticModel semanticModel)
            {
                var invocationExpression = originalSimpleName.Ancestors().OfType<InvocationExpressionSyntax>().FirstOrDefault();

                // Check to see if this is the invocation Expression we wanted to work with
                if (invocationExpression != null && invocationExpression.Expression.GetLastToken() == originalSimpleName.GetLastToken())
                {
                    if (invocationExpression.ArgumentList != null)
                    {
                        foreach (var argument in invocationExpression.ArgumentList.Arguments)
                        {
                            if (argument != null && argument.Expression != null)
                            {
                                var typeinfo = semanticModel.GetTypeInfo(argument.Expression);
                                if (typeinfo.Type != null && typeinfo.Type.TypeKind == TypeKind.Dynamic)
                                {
                                    return true;
                                }
                            }
                        }
                    }
                }

                return false;
            }
開發者ID:RoryVL,項目名稱:roslyn,代碼行數:25,代碼來源:CSharpSimplificationService.Expander.cs

示例12: VisitSimpleName

            private ExpressionSyntax VisitSimpleName(SimpleNameSyntax rewrittenSimpleName, SimpleNameSyntax originalSimpleName)
            {
                _cancellationToken.ThrowIfCancellationRequested();

                // if this is "var", then do not process further
                if (originalSimpleName.IsVar)
                {
                    return rewrittenSimpleName;
                }

                var identifier = rewrittenSimpleName.Identifier;
                ExpressionSyntax newNode = rewrittenSimpleName;

                var isInsideCref = originalSimpleName.AncestorsAndSelf(ascendOutOfTrivia: true).Any(n => n is CrefSyntax);

                ////
                //// 1. if this identifier is an alias, we'll expand it here and replace the node completely.
                ////
                if (!SyntaxFacts.IsAliasQualifier(originalSimpleName))
                {
                    var aliasInfo = _semanticModel.GetAliasInfo(originalSimpleName, _cancellationToken);
                    if (aliasInfo != null)
                    {
                        var aliasTarget = aliasInfo.Target;

                        if (aliasTarget.IsNamespace() && ((INamespaceSymbol)aliasTarget).IsGlobalNamespace)
                        {
                            return rewrittenSimpleName;
                        }

                        // if the enclosing expression is a typeof expression that already contains open type we cannot
                        // we need to insert an open type as well.
                        var typeOfExpression = originalSimpleName.GetAncestor<TypeOfExpressionSyntax>();
                        if (typeOfExpression != null && IsTypeOfUnboundGenericType(_semanticModel, typeOfExpression))
                        {
                            aliasTarget = ((INamedTypeSymbol)aliasTarget).ConstructUnboundGenericType();
                        }

                        // the expanded form replaces the current identifier name.
                        var replacement = FullyQualifyIdentifierName(
                            aliasTarget,
                            newNode,
                            originalSimpleName,
                            replaceNode: true,
                            isInsideCref: isInsideCref,
                            omitLeftHandSide: false)
                                .WithAdditionalAnnotations(Simplifier.Annotation);

                        // We replace the simple name completely, so we can't continue and rename the token
                        // with a RenameLocationAnnotation.
                        // There's also no way of removing annotations, so we just add a DoNotRenameAnnotation.
                        if (replacement.Kind() == SyntaxKind.AliasQualifiedName)
                        {
                            var qualifiedReplacement = (AliasQualifiedNameSyntax)replacement;

                            var newIdentifier = identifier.CopyAnnotationsTo(qualifiedReplacement.Name.Identifier);

                            if (_annotationForReplacedAliasIdentifier != null)
                            {
                                newIdentifier = newIdentifier.WithAdditionalAnnotations(_annotationForReplacedAliasIdentifier);
                            }

                            var aliasAnnotationInfo = AliasAnnotation.Create(aliasInfo.Name);

                            newIdentifier = newIdentifier.WithAdditionalAnnotations(aliasAnnotationInfo);

                            replacement = replacement.ReplaceNode(
                                    qualifiedReplacement.Name,
                                    qualifiedReplacement.Name.WithIdentifier(newIdentifier));

                            replacement = newNode.CopyAnnotationsTo(replacement);

                            var firstReplacementToken = replacement.GetFirstToken(true, false, true, true);
                            var firstOriginalToken = originalSimpleName.GetFirstToken(true, false, true, true);
                            SyntaxToken tokenWithLeadingWhitespace;
                            if (TryAddLeadingElasticTriviaIfNecessary(firstReplacementToken, firstOriginalToken, out tokenWithLeadingWhitespace))
                            {
                                replacement = replacement.ReplaceToken(firstOriginalToken, tokenWithLeadingWhitespace);
                            }

                            replacement = AppendElasticTriviaIfNecessary(replacement, originalSimpleName);

                            return replacement;
                        }

                        if (replacement.Kind() == SyntaxKind.QualifiedName)
                        {
                            var qualifiedReplacement = (QualifiedNameSyntax)replacement;

                            var newIdentifier = identifier.CopyAnnotationsTo(qualifiedReplacement.Right.Identifier);

                            if (_annotationForReplacedAliasIdentifier != null)
                            {
                                newIdentifier = newIdentifier.WithAdditionalAnnotations(_annotationForReplacedAliasIdentifier);
                            }

                            var aliasAnnotationInfo = AliasAnnotation.Create(aliasInfo.Name);

                            newIdentifier = newIdentifier.WithAdditionalAnnotations(aliasAnnotationInfo);

//.........這裏部分代碼省略.........
開發者ID:RoryVL,項目名稱:roslyn,代碼行數:101,代碼來源:CSharpSimplificationService.Expander.cs

示例13: TypeArgumentSymbolsPresentInName

            private IList<ISymbol> TypeArgumentSymbolsPresentInName(SimpleNameSyntax simpleName)
            {
                List<ISymbol> typeArgumentSymbols = new List<ISymbol>();
                var typeArgumentListSyntax = simpleName.DescendantNodesAndSelf().Where(n => n is TypeArgumentListSyntax);
                foreach (var typeArgumentList in typeArgumentListSyntax)
                {
                    var castedTypeArgument = (TypeArgumentListSyntax)typeArgumentList;
                    foreach (var typeArgument in castedTypeArgument.Arguments)
                    {
                        var symbol = _semanticModel.GetSymbolInfo(typeArgument).Symbol;
                        if (symbol != null && !typeArgumentSymbols.Contains(symbol))
                        {
                            typeArgumentSymbols.Add(symbol);
                        }
                    }
                }

                return typeArgumentSymbols;
            }
開發者ID:RoryVL,項目名稱:roslyn,代碼行數:19,代碼來源:CSharpSimplificationService.Expander.cs

示例14: ReplaceStaticCallWithExtionMethodCall

 private static CompilationUnitSyntax ReplaceStaticCallWithExtionMethodCall(CompilationUnitSyntax root, InvocationExpressionSyntax staticInvocationExpression, ExpressionSyntax sourceExpression, SimpleNameSyntax methodName, ArgumentListSyntax argumentList)
 {
     var extensionInvocationExpression = CallExtensionMethodAsExtensionAnalyzer.CreateInvocationExpression(sourceExpression, methodName, argumentList)
         .WithLeadingTrivia(staticInvocationExpression.GetLeadingTrivia());
     return root.ReplaceNode(staticInvocationExpression, extensionInvocationExpression);
 }
開發者ID:haroldhues,項目名稱:code-cracker,代碼行數:6,代碼來源:CallExtensionMethodAsExtensionCodeFixProvider.cs

示例15: SimpleNameTranslation

 public SimpleNameTranslation(SimpleNameSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
 {
 }
開發者ID:asthomas,項目名稱:TypescriptSyntaxPaste,代碼行數:3,代碼來源:SimpleNameTranslation.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.SimpleNameSyntax類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。