• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Syntax.BaseMethodDeclarationSyntax类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.BaseMethodDeclarationSyntax的典型用法代码示例。如果您正苦于以下问题:C# BaseMethodDeclarationSyntax类的具体用法?C# BaseMethodDeclarationSyntax怎么用?C# BaseMethodDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BaseMethodDeclarationSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了BaseMethodDeclarationSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: IsCandidateForRemoval

 private static bool IsCandidateForRemoval(BaseMethodDeclarationSyntax methodOrConstructor, SemanticModel semanticModel)
 {
     if (methodOrConstructor.Modifiers.Any(m => m.ValueText == "partial" || m.ValueText == "override")
         || !methodOrConstructor.ParameterList.Parameters.Any()
         || methodOrConstructor.Body == null)
         return false;
     var method = methodOrConstructor as MethodDeclarationSyntax;
     if (method != null)
     {
         if (method.ExplicitInterfaceSpecifier != null) return false;
         var methodSymbol = semanticModel.GetDeclaredSymbol(method);
         if (methodSymbol == null) return false;
         var typeSymbol = methodSymbol.ContainingType;
         if (typeSymbol.AllInterfaces.SelectMany(i => i.GetMembers())
             .Any(member => methodSymbol.Equals(typeSymbol.FindImplementationForInterfaceMember(member))))
             return false;
         if (IsEventHandlerLike(method, semanticModel)) return false;
     }
     else
     {
         var constructor = methodOrConstructor as ConstructorDeclarationSyntax;
         if (constructor != null)
         {
             if (IsSerializationConstructor(constructor, semanticModel)) return false;
         }
         else
         {
             return false;
         }
     }
     return true;
 }
开发者ID:Cadums01,项目名称:code-cracker,代码行数:32,代码来源:UnusedParametersAnalyzer.cs


示例2: IsInBody

        /// <summary>
        /// A position is inside a body if it is inside the block or expression
        /// body. 
        ///
        /// A position is considered to be inside a block if it is on or after
        /// the open brace and strictly before the close brace. A position is
        /// considered to be inside an expression body if it is on or after
        /// the '=>' and strictly before the semicolon.
        /// </summary>
        internal static bool IsInBody(int position, BaseMethodDeclarationSyntax method)
        {
            var exprOpt = method.GetExpressionBodySyntax();

            return IsInExpressionBody(position, exprOpt, method.SemicolonToken)
                || IsInBlock(position, method.Body);
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:16,代码来源:LookupPosition.cs


示例3: BaseMethodDeclarationTranslation

 public BaseMethodDeclarationTranslation(BaseMethodDeclarationSyntax syntax,  SyntaxTranslation parent) : base(syntax, parent)
 {
     ParameterList = syntax.ParameterList.Get<ParameterListTranslation>(this);
     Modifiers = syntax.Modifiers.Get(this);
     Body = syntax.Body.Get<BlockTranslation>(this);
     SemicolonToken = syntax.SemicolonToken.Get(this);
 }
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:7,代码来源:BaseMethodDeclarationTranslation.cs


示例4: IsInMethodDeclaration

        internal static bool IsInMethodDeclaration(int position, BaseMethodDeclarationSyntax methodDecl)
        {
            Debug.Assert(methodDecl != null);

            var body = methodDecl.Body;
            SyntaxToken lastToken = body == null ? methodDecl.SemicolonToken : body.CloseBraceToken;
            return IsBeforeToken(position, methodDecl, lastToken);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:8,代码来源:LookupPosition.cs


示例5: MethodSummary

 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="context">AnalysisContext</param>
 /// <param name="method">BaseMethodDeclarationSyntax</param>
 /// <param name="parameterTypes">ITypeSymbols</param>
 private MethodSummary(AnalysisContext context, BaseMethodDeclarationSyntax method,
     IDictionary<int, ISet<ITypeSymbol>> parameterTypes)
 {
     this.Id = MethodSummary.IdCounter++;
     this.AnalysisContext = context;
     this.SemanticModel = context.Compilation.GetSemanticModel(method.SyntaxTree);
     this.Method = method;
     this.SideEffectsInfo = new MethodSideEffectsInfo(this);
     this.ResolveMethodParameterTypes(parameterTypes);
 }
开发者ID:yonglehou,项目名称:PSharp,代码行数:16,代码来源:MethodSummary.cs


示例6: IsNoCompile

 public static bool IsNoCompile(this SemanticModel model, BaseMethodDeclarationSyntax syntax)
 {
     foreach (var attrListSyntax in syntax.AttributeLists)
     {
         foreach (var attr in attrListSyntax.Attributes)
         {
             var type = model.GetTypeInfo(attr);
             if (type.Type.IsSameType(nameof(JavaScript), nameof(NoCompileAttribute)))
                 return true;
         }
     }
     return false;
 }
开发者ID:rexzh,项目名称:SharpJs,代码行数:13,代码来源:SemanticModelExtension.cs


示例7: CanBeMadeStatic

		public bool CanBeMadeStatic(BaseMethodDeclarationSyntax method)
		{
			if (method.Modifiers.Any(SyntaxKind.StaticKeyword)
				|| method.Body == null
				|| !method.Body.ChildNodes().Any())
			{
				return false;
			}

			var bodyNodes = method.Body.ChildNodes();
			var dataflow = _model.AnalyzeDataFlow(bodyNodes.First(), bodyNodes.Last());
			var hasThisReference = dataflow.DataFlowsIn
				.Any(x => x.Kind == SymbolKind.Parameter && x.Name == SyntaxFactory.Token(SyntaxKind.ThisKeyword).ToFullString());
			return !hasThisReference;
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:15,代码来源:SemanticAnalyzer.cs


示例8: RegisterActionForDestructor

 private static void RegisterActionForDestructor(CodeFixContext context, SyntaxNode root, BaseMethodDeclarationSyntax method)
 {
     context.RegisterCodeFix(
         CodeAction.Create(
             TitleRemoveDestructor,
             c =>
             {
                 var newRoot = root.RemoveNode(
                     method,
                     SyntaxRemoveOptions.KeepNoTrivia);
                 return Task.FromResult(context.Document.WithSyntaxRoot(newRoot));
             },
             TitleRemoveDestructor),
         context.Diagnostics);
 }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:15,代码来源:RedundancyInConstructorDestructorDeclarationCodeFixProvider.cs


示例9: TraceInfo

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="method">BaseMethodDeclarationSyntax</param>
        /// <param name="machine">StateMachine</param>
        /// <param name="state">MachineState</param>
        /// <param name="payload">ISymbol</param>
        internal TraceInfo(BaseMethodDeclarationSyntax method, StateMachine machine,
            MachineState state, ISymbol payload)
        {
            this.ErrorTrace = new List<ErrorTraceStep>();
            this.CallTrace = new List<CallTraceStep>();

            if (method == null)
            {
                this.Method = null;
            }
            else if (method is MethodDeclarationSyntax)
            {
                this.Method = (method as MethodDeclarationSyntax).Identifier.ValueText;
            }
            else if (method is ConstructorDeclarationSyntax)
            {
                this.Method = (method as ConstructorDeclarationSyntax).Identifier.ValueText;
            }

            if (machine == null)
            {
                this.Machine = null;
            }
            else
            {
                this.Machine = machine.Name;
            }

            if (state == null)
            {
                this.State = null;
            }
            else
            {
                this.State = state.Name;
            }

            if (payload == null)
            {
                this.Payload = null;
            }
            else
            {
                this.Payload = payload.Name;
            }
        }
开发者ID:yonglehou,项目名称:PSharp,代码行数:53,代码来源:TraceInfo.cs


示例10: IsInBody

 /// <summary>
 /// A position is inside a body if it is inside the block or expression
 /// body. 
 ///
 /// A position is considered to be inside a block if it is on or after
 /// the open brace and strictly before the close brace. A position is
 /// considered to be inside an expression body if it is on or after
 /// the '=>' and strictly before the semicolon.
 /// </summary>
 internal static bool IsInBody(int position, BaseMethodDeclarationSyntax method)
 {
     ArrowExpressionClauseSyntax expressionBodyOpt = null;
     switch (method.Kind)
     {
         case SyntaxKind.ConversionOperatorDeclaration:
             expressionBodyOpt = ((ConversionOperatorDeclarationSyntax)method).ExpressionBody;
             break;
         case SyntaxKind.OperatorDeclaration:
             expressionBodyOpt = ((OperatorDeclarationSyntax)method).ExpressionBody;
             break;
         case SyntaxKind.MethodDeclaration:
             expressionBodyOpt = ((MethodDeclarationSyntax)method).ExpressionBody;
             break;
         default:
             break;
     }
     return IsInExpressionBody(position, expressionBodyOpt, method.SemicolonToken)
         || IsInBlock(position, method.Body);
 }
开发者ID:afrog33k,项目名称:csnative,代码行数:29,代码来源:LookupPosition.cs


示例11: GetUnusedParameters

		public IEnumerable<ParameterSyntax> GetUnusedParameters(BaseMethodDeclarationSyntax method)
		{
			if (method.ParameterList.Parameters.Count == 0 || method.Body == null || !method.Body.ChildNodes().Any())
			{
				return new ParameterSyntax[0];
			}

			var bodyNodes = method.Body.ChildNodes();
			var dataflow = _model.AnalyzeDataFlow(bodyNodes.First(), bodyNodes.Last());

			var usedParameterNames = dataflow.DataFlowsIn
				.Where(x => x.Kind == SymbolKind.Parameter)
				.Select(x => x.Name)
				.AsArray();

			var unusedParameters = method.ParameterList.Parameters
				.Where(p => !usedParameterNames.Contains(p.Identifier.ValueText))
				.AsArray();
			return unusedParameters;
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:20,代码来源:SemanticAnalyzer.cs


示例12: ConvertToExpressionBodiedMemberAsync

        private static async Task<Document> ConvertToExpressionBodiedMemberAsync(
            Document document,
            BaseMethodDeclarationSyntax declaration,
            CancellationToken cancellationToken)
        {
            var body = declaration.Body;
            var returnStatement = body.Statements[0] as ReturnStatementSyntax;

            var arrowExpression = SyntaxFactory.ArrowExpressionClause(returnStatement.Expression);

            var newDeclaration = declaration;

            newDeclaration = ((dynamic)newDeclaration)
                .WithBody(null)
                .WithExpressionBody(arrowExpression)
                .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));

            newDeclaration = newDeclaration.WithAdditionalAnnotations(Formatter.Annotation);

            return await ReplaceNodeAsync(document, declaration, newDeclaration, cancellationToken);
        }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:21,代码来源:ConvertToExpressionBodiedMemberCodeFixProvider.cs


示例13: HandleBaseMethodDeclaration

        private static void HandleBaseMethodDeclaration(
            SyntaxNodeAnalysisContext context,
            BaseMethodDeclarationSyntax baseMethodDeclarationSyntax)
        {
            var parameterListSyntax =
                baseMethodDeclarationSyntax.ParameterList;

            if (parameterListSyntax != null && !parameterListSyntax.Parameters.Any())
            {
                if (!parameterListSyntax.OpenParenToken.IsMissing &&
                    !parameterListSyntax.CloseParenToken.IsMissing)
                {
                    CheckIfLocationOfOpenAndCloseTokensAreTheSame(context, parameterListSyntax.OpenParenToken, parameterListSyntax.CloseParenToken);
                }
            }
        }
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:16,代码来源:SA1112ClosingParenthesisMustBeOnLineOfOpeningParenthesis.cs


示例14: AppendParameters

		private void AppendParameters(BaseMethodDeclarationSyntax syntax, StringBuilder builder)
		{
			builder.Append("(");
			var parameterList = syntax.ParameterList;
			if (parameterList != null)
			{
				var parameters = parameterList.Parameters;
				Func<ParameterSyntax, string> selector = parameters.Any() 
					? new Func<ParameterSyntax, string>(TypeNameSelector) 
					: x => string.Empty;
				
				var parameterNames = string.Join(", ", parameters.Select(selector).Where(x => !string.IsNullOrWhiteSpace(x)));
				builder.Append(parameterNames);
			}

			builder.Append(")");
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:17,代码来源:MemberNameResolver.cs


示例15: GetDeclaredSymbol

 public override IMethodSymbol GetDeclaredSymbol(BaseMethodDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     // Can't define method inside member.
     return null;
 }
开发者ID:orthoxerox,项目名称:roslyn,代码行数:5,代码来源:MemberSemanticModel.cs


示例16: GetEndPoint

            private VirtualTreePoint GetEndPoint(SourceText text, BaseMethodDeclarationSyntax node, EnvDTE.vsCMPart part)
            {
                int endPosition;

                switch (part)
                {
                    case EnvDTE.vsCMPart.vsCMPartName:
                    case EnvDTE.vsCMPart.vsCMPartAttributes:
                    case EnvDTE.vsCMPart.vsCMPartHeader:
                    case EnvDTE.vsCMPart.vsCMPartWhole:
                    case EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter:
                    case EnvDTE.vsCMPart.vsCMPartHeaderWithAttributes:
                        throw Exceptions.ThrowENotImpl();

                    case EnvDTE.vsCMPart.vsCMPartAttributesWithDelimiter:
                        if (node.AttributeLists.Count == 0)
                        {
                            throw Exceptions.ThrowEFail();
                        }

                        endPosition = node.AttributeLists.Last().GetLastToken().Span.End;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartWholeWithAttributes:
                        endPosition = node.Span.End;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartNavigate:
                        if (node.Body != null && !node.Body.CloseBraceToken.IsMissing)
                        {
                            return GetBodyEndPoint(text, node.Body.CloseBraceToken);
                        }
                        else
                        {
                            switch (node.Kind())
                            {
                                case SyntaxKind.MethodDeclaration:
                                    endPosition = ((MethodDeclarationSyntax)node).Identifier.Span.End;
                                    break;
                                case SyntaxKind.ConstructorDeclaration:
                                    endPosition = ((ConstructorDeclarationSyntax)node).Identifier.Span.End;
                                    break;
                                case SyntaxKind.DestructorDeclaration:
                                    endPosition = ((DestructorDeclarationSyntax)node).Identifier.Span.End;
                                    break;
                                case SyntaxKind.ConversionOperatorDeclaration:
                                    endPosition = ((ConversionOperatorDeclarationSyntax)node).ImplicitOrExplicitKeyword.Span.End;
                                    break;
                                case SyntaxKind.OperatorDeclaration:
                                    endPosition = ((OperatorDeclarationSyntax)node).OperatorToken.Span.End;
                                    break;
                                default:
                                    endPosition = node.GetFirstTokenAfterAttributes().Span.End;
                                    break;
                            }
                        }

                        break;

                    case EnvDTE.vsCMPart.vsCMPartBody:
                        if (node.Body == null || node.Body.OpenBraceToken.IsMissing || node.Body.CloseBraceToken.IsMissing)
                        {
                            throw Exceptions.ThrowEFail();
                        }

                        return GetBodyEndPoint(text, node.Body.CloseBraceToken);

                    default:
                        throw Exceptions.ThrowEInvalidArg();
                }

                return new VirtualTreePoint(node.SyntaxTree, text, endPosition);
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:73,代码来源:CSharpCodeModelService.NodeLocator.cs


示例17: CallTraceStep

 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="method">Method</param>
 /// <param name="invocation">Invocation</param>
 internal CallTraceStep(BaseMethodDeclarationSyntax method, ExpressionSyntax invocation)
 {
     this.Method = method;
     this.Invocation = invocation;
 }
开发者ID:yonglehou,项目名称:PSharp,代码行数:10,代码来源:CallTraceStep.cs


示例18: CompareMethodDeclarations

            private bool CompareMethodDeclarations(
                BaseMethodDeclarationSyntax oldMethod,
                BaseMethodDeclarationSyntax newMethod,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldMethod != null && newMethod != null);

                if (!StringComparer.Ordinal.Equals(CodeModelService.GetName(oldMethod), CodeModelService.GetName(newMethod)))
                {
                    var change = CompareRenamedDeclarations(
                        CompareParameters,
                        oldMethod.ParameterList.Parameters.AsReadOnlyList(),
                        newMethod.ParameterList.Parameters.AsReadOnlyList(),
                        oldMethod,
                        newMethod,
                        newNodeParent,
                        eventQueue);

                    if (change == DeclarationChange.NameOnly)
                    {
                        EnqueueChangeEvent(newMethod, newNodeParent, CodeModelEventType.Rename, eventQueue);
                    }

                    return false;
                }
                else
                {
                    bool same = true;

                    if (!CompareModifiers(oldMethod, newMethod))
                    {
                        same = false;
                        EnqueueChangeEvent(newMethod, newNodeParent, CodeModelEventType.Unknown, eventQueue);
                    }

                    if (!CompareTypes(GetReturnType(oldMethod), GetReturnType(newMethod)))
                    {
                        same = false;
                        EnqueueChangeEvent(newMethod, newNodeParent, CodeModelEventType.TypeRefChange, eventQueue);
                    }

                    same &= CompareChildren(
                        CompareAttributeLists,
                        oldMethod.AttributeLists.AsReadOnlyList(),
                        newMethod.AttributeLists.AsReadOnlyList(),
                        newMethod,
                        CodeModelEventType.Unknown,
                        eventQueue);

                    same &= CompareChildren(
                        CompareParameters,
                        oldMethod.ParameterList.Parameters.AsReadOnlyList(),
                        newMethod.ParameterList.Parameters.AsReadOnlyList(),
                        newMethod,
                        CodeModelEventType.SigChange,
                        eventQueue);

                    return same;
                }
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:61,代码来源:CSharpCodeModelService.CodeModelEventCollector.cs


示例19: TryGetSpeculativeSemanticModelForMethodBodyCore

        internal sealed override bool TryGetSpeculativeSemanticModelForMethodBodyCore(SyntaxTreeSemanticModel parentModel, int position, BaseMethodDeclarationSyntax method, out SemanticModel speculativeModel)
        {
            position = CheckAndAdjustPosition(position);

            var model = this.GetMemberModel(position);
            if (model != null)
            {
                return model.TryGetSpeculativeSemanticModelForMethodBodyCore(parentModel, position, method, out speculativeModel);
            }

            speculativeModel = null;
            return false;
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:13,代码来源:SyntaxTreeSemanticModel.cs


示例20: HandleBaseMethodDeclaration

        private static void HandleBaseMethodDeclaration(
            SyntaxNodeAnalysisContext context,
            BaseMethodDeclarationSyntax baseMethodDeclarationSyntax)
        {
            if (baseMethodDeclarationSyntax.ParameterList == null ||
                baseMethodDeclarationSyntax.ParameterList.IsMissing ||
                !baseMethodDeclarationSyntax.ParameterList.Parameters.Any())
            {
                return;
            }

            var lastParameter = baseMethodDeclarationSyntax.ParameterList
                .Parameters
                .Last();

            if (!baseMethodDeclarationSyntax.ParameterList.CloseParenToken.IsMissing)
            {
                CheckIfLocationOfLastArgumentOrParameterAndCloseTokenAreTheSame(context, lastParameter, baseMethodDeclarationSyntax.ParameterList.CloseParenToken);
            }
        }
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:20,代码来源:SA1111ClosingParenthesisMustBeOnLineOfLastParameter.cs



注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.BaseMethodDeclarationSyntax类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Syntax.ClassDeclarationSyntax类代码示例发布时间:2022-05-26
下一篇:
C# Syntax.AttributeSyntax类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap