本文整理汇总了C#中CompilationStartAnalysisContext类的典型用法代码示例。如果您正苦于以下问题:C# CompilationStartAnalysisContext类的具体用法?C# CompilationStartAnalysisContext怎么用?C# CompilationStartAnalysisContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationStartAnalysisContext类属于命名空间,在下文中一共展示了CompilationStartAnalysisContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeCompilationStart
private void AnalyzeCompilationStart(CompilationStartAnalysisContext csContext)
{
// Get named type symbols for targetted exception types
ImmutableHashSet<INamedTypeSymbol> exceptionTypes = s_exceptionTypeNames
.Select(name => csContext.Compilation.GetTypeByMetadataName(name))
.Where(t => t != null)
.ToImmutableHashSet();
if (!exceptionTypes.IsEmpty)
{
// register symbol action for named types
csContext.RegisterSymbolAction(saContext =>
{
var symbol = (INamedTypeSymbol)saContext.Symbol;
// skip public symbols
if (symbol.IsPublic()) return;
// only report if base type matches
if (symbol.BaseType != null && exceptionTypes.Contains(symbol.BaseType))
{
saContext.ReportDiagnostic(symbol.CreateDiagnostic(Rule));
}
},
SymbolKind.NamedType);
}
}
示例2: HandleCompilationStart
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
{
context.RegisterSyntaxNodeActionHonorExclusions(HandleTypeDeclaration, SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKind.InterfaceDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandleMethodDeclaration, SyntaxKind.MethodDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandleDelegateDeclaration, SyntaxKind.DelegateDeclaration);
}
示例3: HandleCompilationStart
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
{
context.RegisterSyntaxNodeActionHonorExclusions(HandleDeclaration, SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKind.InterfaceDeclaration,
SyntaxKind.EnumDeclaration, SyntaxKind.DelegateDeclaration, SyntaxKind.FieldDeclaration, SyntaxKind.MethodDeclaration,
SyntaxKind.PropertyDeclaration, SyntaxKind.EventDeclaration, SyntaxKind.EventFieldDeclaration, SyntaxKind.IndexerDeclaration,
SyntaxKind.OperatorDeclaration, SyntaxKind.ConversionOperatorDeclaration, SyntaxKind.ConstructorDeclaration);
}
示例4: Analyze
void Analyze(CompilationStartAnalysisContext compilationContext)
{
var compilation = compilationContext.Compilation;
compilationContext.RegisterSyntaxTreeAction(async delegate (SyntaxTreeAnalysisContext context)
{
try
{
if (!compilation.SyntaxTrees.Contains(context.Tree))
return;
var semanticModel = compilation.GetSemanticModel(context.Tree);
var root = await context.Tree.GetRootAsync(context.CancellationToken).ConfigureAwait(false);
var model = compilationContext.Compilation.GetSemanticModel(context.Tree);
if (model.IsFromGeneratedCode(compilationContext.CancellationToken))
return;
foreach (var type in root.DescendantNodesAndSelf(SkipMembers).OfType<ClassDeclarationSyntax>())
{
var fieldDeclarations = type
.ChildNodes()
.OfType<FieldDeclarationSyntax>()
.Where(f => FieldFilter(model, f))
.SelectMany(fd => fd.Declaration.Variables.Select(v => new { Field = fd, Variable = v, Symbol = semanticModel.GetDeclaredSymbol(v, context.CancellationToken) }));
foreach (var candidateField in fieldDeclarations)
{
context.CancellationToken.ThrowIfCancellationRequested();
// handled by ConvertToConstantIssue
if (candidateField?.Variable?.Initializer != null && semanticModel.GetConstantValue(candidateField.Variable.Initializer.Value, context.CancellationToken).HasValue)
continue;
// user-defined value type -- might be mutable
var field = candidateField.Symbol;
if (field != null && !field.GetReturnType().IsReferenceType)
{
if (field.GetReturnType().IsDefinedInSource())
{
continue;
}
}
bool wasAltered = false;
bool wasUsed = false;
foreach (var member in type.Members)
{
if (member == candidateField.Field)
continue;
if (IsAltered(model, member, candidateField.Symbol, context.CancellationToken, out wasUsed))
{
wasAltered = true;
break;
}
}
if (!wasAltered && wasUsed)
{
context.CancellationToken.ThrowIfCancellationRequested();
context.ReportDiagnostic(Diagnostic.Create(descriptor, candidateField.Variable.Identifier.GetLocation()));
}
}
}
}
catch (Exception) { }
});
}
示例5: HandleCompilationStart
/// <summary>
/// Documentation analysis is done only on compilation start, to delay
/// </summary>
/// <param name="context">the compilation start action.</param>
private void HandleCompilationStart(CompilationStartAnalysisContext context)
{
context.RegisterSyntaxNodeAction(
this.HandleClassOrInterfaceDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKind.ClassDeclaration);
}
示例6: HandleCompilationStart
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
{
context.RegisterSyntaxNodeActionHonorExclusions(BaseTypeDeclarationAction, BaseTypeDeclarationKinds);
context.RegisterSyntaxNodeActionHonorExclusions(BasePropertyDeclarationAction, BasePropertyDeclarationKinds);
context.RegisterSyntaxNodeActionHonorExclusions(BaseMethodDeclarationAction, BaseMethodDeclarationKinds);
context.RegisterSyntaxNodeActionHonorExclusions(NamespaceDeclarationAction, SyntaxKind.NamespaceDeclaration);
}
示例7: AnalyzeCompilationStart
private static void AnalyzeCompilationStart(CompilationStartAnalysisContext context)
{
ImmutableHashSet<INamedTypeSymbol> badBaseTypes = s_badBaseTypesToMessage.Keys
.Select(bt => context.Compilation.GetTypeByMetadataName(bt))
.Where(bt => bt != null)
.ToImmutableHashSet();
if (badBaseTypes.Count > 0)
{
context.RegisterSymbolAction((saContext) =>
{
var namedTypeSymbol = saContext.Symbol as INamedTypeSymbol;
if (namedTypeSymbol.BaseType != null && badBaseTypes.Contains(namedTypeSymbol.BaseType))
{
string baseTypeName = namedTypeSymbol.BaseType.ToDisplayString();
Debug.Assert(s_badBaseTypesToMessage.ContainsKey(baseTypeName));
string message = string.Format(s_badBaseTypesToMessage[baseTypeName], namedTypeSymbol.ToDisplayString(), baseTypeName);
Diagnostic diagnostic = Diagnostic.Create(Rule, namedTypeSymbol.Locations.First(), namedTypeSymbol.Locations.Skip(1), message);
saContext.ReportDiagnostic(diagnostic);
}
}
, SymbolKind.NamedType);
}
}
示例8: HandleCompilationStart
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
{
context.RegisterSyntaxNodeActionHonorExclusions(HandleSyntaxNode, SyntaxKind.MethodDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandleSyntaxNode, SyntaxKind.ConstructorDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandleSyntaxNode, SyntaxKind.DelegateDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandleSyntaxNode, SyntaxKind.IndexerDeclaration);
}
示例9: RegisterImmutableArrayAction
protected override void RegisterImmutableArrayAction(CompilationStartAnalysisContext context, INamedTypeSymbol immutableArrayOfTType)
{
context.RegisterCodeBlockStartAction<SyntaxKind>(
c => c.RegisterSyntaxNodeAction(
c2 => AnalyzeCollectionInitializerExpression(c2, immutableArrayOfTType),
SyntaxKind.CollectionInitializerExpression));
}
开发者ID:jwendl,项目名称:CoreFxAnalyzers,代码行数:7,代码来源:DoNotUseImmutableArrayCollectionInitializerAnalyzer.cs
示例10: RegisterOperationAction
/// <summary>Called once at compilation start to register actions in the compilation context.</summary>
/// <param name="context">The analysis context.</param>
internal void RegisterOperationAction(CompilationStartAnalysisContext context)
{
context.RegisterOperationAction(
(operationContext) =>
{
IArrayCreationExpression arrayCreation = (IArrayCreationExpression)operationContext.Operation;
// ToDo: Need to suppress analysis of array creation expressions within attribute applications.
// Detect array creation expression that have rank 1 and size 0. Such expressions
// can be replaced with Array.Empty<T>(), provided that the element type can be a generic type argument.
if (arrayCreation.DimensionSizes.Length == 1
//// Pointer types can't be generic type arguments.
&& arrayCreation.ElementType.TypeKind != TypeKind.Pointer)
{
Optional<object> arrayLength = arrayCreation.DimensionSizes[0].ConstantValue;
if (arrayLength.HasValue &&
arrayLength.Value is int &&
(int)arrayLength.Value == 0)
{
Report(operationContext, arrayCreation.Syntax);
}
}
},
OperationKind.ArrayCreationExpression);
}
示例11: HandleCompilationStart
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
{
context.RegisterSyntaxNodeActionHonorExclusions(HandleBaseTypeDeclarations, SyntaxKind.ClassDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.StructDeclaration, SyntaxKind.EnumDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandlePropertyLikeDeclarations, SyntaxKind.PropertyDeclaration, SyntaxKind.EventDeclaration, SyntaxKind.IndexerDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandleMethodLikeDeclarations, SyntaxKind.MethodDeclaration, SyntaxKind.ConstructorDeclaration, SyntaxKind.DestructorDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandleNamespaceDeclarations, SyntaxKind.NamespaceDeclaration);
}
示例12: GetAnalyzer
protected override SymbolAndNodeAnalyzer GetAnalyzer(CompilationStartAnalysisContext context, CompilationSecurityTypes types, Version targetFrameworkVersion)
{
SymbolAndNodeAnalyzer analyzer = new SymbolAndNodeAnalyzer(types, CSharpSyntaxNodeHelper.Default, targetFrameworkVersion);
context.RegisterSyntaxNodeAction(analyzer.AnalyzeNode, SyntaxKind.MethodDeclaration, SyntaxKind.ConstructorDeclaration);
return analyzer;
}
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:7,代码来源:CSharpDoNotUseInsecureDtdProcessingInApiDesigner.cs
示例13: HandleCompilationStart
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
{
context.RegisterSyntaxNodeActionHonorExclusions(HandleMethodDeclaration, SyntaxKind.MethodDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandleConstructorDeclaration, SyntaxKind.ConstructorDeclaration);
context.RegisterSyntaxNodeActionHonorExclusions(HandleInvocationExpression, SyntaxKind.InvocationExpression);
context.RegisterSyntaxNodeActionHonorExclusions(HandleObjectCreationExpression, SyntaxKind.ObjectCreationExpression);
}
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:SA1112ClosingParenthesisMustBeOnLineOfOpeningParenthesis.cs
示例14: OnCompilationStart
private void OnCompilationStart(CompilationStartAnalysisContext context)
{
var immutableArrayType = context.Compilation.GetTypeByMetadataName(ImmutableArrayMetadataName);
if (immutableArrayType != null)
{
context.RegisterSyntaxNodeAction(syntaxContext => AnalyzeCall(syntaxContext, immutableArrayType), SyntaxKind.InvocationExpression);
}
}
示例15: GetAnalyzer
protected override Analyzer GetAnalyzer(CompilationStartAnalysisContext context, CompilationSecurityTypes cryptTypes)
{
Analyzer analyzer = new Analyzer(cryptTypes);
context.RegisterSyntaxNodeAction(analyzer.AnalyzeNode,
SyntaxKind.InvocationExpression,
SyntaxKind.ObjectCreationExpression);
return analyzer;
}