本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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);
}
示例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(")");
}
示例15: GetDeclaredSymbol
public override IMethodSymbol GetDeclaredSymbol(BaseMethodDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
{
// Can't define method inside member.
return null;
}