当前位置: 首页>>代码示例>>C#>>正文


C# Syntax.BaseMethodDeclarationSyntax类代码示例

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


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


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