本文整理汇总了C#中CompilationStartAnalysisContext类的典型用法代码示例。如果您正苦于以下问题:C# CompilationStartAnalysisContext类的具体用法?C# CompilationStartAnalysisContext怎么用?C# CompilationStartAnalysisContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationStartAnalysisContext类属于命名空间,在下文中一共展示了CompilationStartAnalysisContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:27,代码来源:ExceptionsShouldBePublic.cs
示例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);
}
开发者ID:endjin,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:SA1618GenericTypeParametersMustBeDocumented.cs
示例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);
}
开发者ID:robinsedlaczek,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:SA1206DeclarationKeywordsMustFollowOrder.cs
示例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) { }
});
}
开发者ID:vcsjones,项目名称:RefactoringEssentials,代码行数:60,代码来源:FieldCanBeMadeReadOnlyAnalyzer.cs
示例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);
}
开发者ID:jimmymain,项目名称:Documentation.Analyzers,代码行数:11,代码来源:DocumentationClassAnalyser.cs
示例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);
}
开发者ID:hexuefengx,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:SA1502ElementMustNotBeOnASingleLine.cs
示例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);
}
}
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:25,代码来源:TypesShouldNotExtendCertainBaseTypes.cs
示例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);
}
开发者ID:Noryoko,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:SA1611ElementParametersMustBeDocumented.cs
示例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);
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:29,代码来源:EmptyArrayAnalyzer.cs
示例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);
}
开发者ID:Noryoko,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:SA1502ElementMustNotBeOnASingleLine.cs
示例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);
}
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:8,代码来源:ImmutableCollectionAnalyzer.cs
示例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;
}
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:8,代码来源:CSharpDoNotUseInsecureCyrptographicAlgorithms.cs
示例16: HandleCompilationStart
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
{
// handle everything except nameof
context.RegisterSyntaxTreeActionHonorExclusions(HandleSyntaxTree);
// handle nameof (which appears as an invocation expression??)
context.RegisterSyntaxNodeActionHonorExclusions(HandleInvocationExpressionSyntax, SyntaxKind.InvocationExpression);
}
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:8,代码来源:SA1000KeywordsMustBeSpacedCorrectly.cs
示例17: HandleCompilationStart
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
{
context.RegisterSyntaxNodeActionHonorExclusions(HandleIfStatement, SyntaxKind.IfStatement);
context.RegisterSyntaxNodeActionHonorExclusions(HandleDoStatement, SyntaxKind.DoStatement);
context.RegisterSyntaxNodeActionHonorExclusions(HandleWhileStatement, SyntaxKind.WhileStatement);
context.RegisterSyntaxNodeActionHonorExclusions(HandleForStatement, SyntaxKind.ForStatement);
context.RegisterSyntaxNodeActionHonorExclusions(HandleForEachStatement, SyntaxKind.ForEachStatement);
}
开发者ID:endjin,项目名称:StyleCopAnalyzers,代码行数:8,代码来源:SA1519CurlyBracketsMustNotBeOmittedFromMultiLineChildStatement.cs
示例18: OnCompilationStart
public override void OnCompilationStart(CompilationStartAnalysisContext context)
{
SRSymbol = context.Compilation.GetTypeByMetadataName("System.SR");
if (SRSymbol != null)
{
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.InvocationExpression);
}
}
开发者ID:dsgouda,项目名称:buildtools,代码行数:8,代码来源:ResourceUsageAnalyzer.cs
示例19: HandleCompilationStart
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
{
context.RegisterSyntaxNodeActionHonorExclusions(HandleBinaryExpression, SyntaxKind.EqualsExpression);
context.RegisterSyntaxNodeActionHonorExclusions(HandleBinaryExpression, SyntaxKind.NotEqualsExpression);
context.RegisterSyntaxNodeActionHonorExclusions(HandleBinaryExpression, SyntaxKind.GreaterThanExpression);
context.RegisterSyntaxNodeActionHonorExclusions(HandleBinaryExpression, SyntaxKind.LessThanExpression);
context.RegisterSyntaxNodeActionHonorExclusions(HandleBinaryExpression, SyntaxKind.GreaterThanOrEqualExpression);
context.RegisterSyntaxNodeActionHonorExclusions(HandleBinaryExpression, SyntaxKind.LessThanOrEqualExpression);
}
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:9,代码来源:SA1131UseReadableConditions.cs
示例20: OnCompilationStart
private static void OnCompilationStart(CompilationStartAnalysisContext context)
{
INamedTypeSymbol objectType = context.Compilation.GetSpecialType(SpecialType.System_Object);
INamedTypeSymbol equatableType = context.Compilation.GetTypeByMetadataName(IEquatableMetadataName);
if (objectType != null && equatableType != null)
{
context.RegisterSymbolAction(c => AnalyzeSymbol(c, equatableType), SymbolKind.NamedType);
}
}
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:9,代码来源:EquatableAnalyzer.cs
注:本文中的CompilationStartAnalysisContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论