private void Analyzer(SyntaxNodeAnalysisContext context) { var mainConstrutor = new MethodInformation( "Uri", "System.Uri.Uri(string)", args => { { if (args[0] == null) { return; } new Uri(args[0].ToString()); } } ); var constructorWithUriKind = new MethodInformation( "Uri", "System.Uri.Uri(string, System.UriKind)", args => { if (args[0] == null) { return; } new Uri(args[0].ToString(), (UriKind)args[1]); } ); var checker = new MethodChecker(context, Rule); checker.AnalyzeConstrutor(mainConstrutor); checker.AnalyzeConstrutor(constructorWithUriKind); }
private void Analyzer(SyntaxNodeAnalysisContext context) { var method = new MethodInformation( "Parse", "System.Net.IPAddress.Parse(string)", args => { parseMethodInfo.Value.Invoke(null, new[] { args[0].ToString() }); } ); var checker = new MethodChecker(context, Rule); checker.AnalyzeMethod(method); }
/// <summary> /// Start recording expectations for a method. /// They need to be recorded in order, from method with smallest identifier to largest. /// </summary> /// <param name="method">The 1-based cardinal for referring to methods in data emitted and instrumentation data collected.</param> /// <param name="file">The 1-based cardinal identifying a source file, as collected by the instrumentation.</param> /// <param name="snippet"> /// A short snippet of code capturing the what you expect the span for this method to look like. /// It will be verified against the start of the actual method source span. /// If no snippet is passed in, then snippet validation will be disabled for the whole method (subsequent calls to <c>True</c> or <c>False</c>). /// </param> public MethodChecker Method(int method, int file, string snippet = null, bool expectBodySpan = true) { AddConsoleExpectation($"Method {method}"); AddConsoleExpectation($"File {file}"); var result = new MethodChecker(this, noSnippets: snippet == null); // Most methods have a span that indicates that the method has been entered. if (expectBodySpan) { result = result.True(snippet); } if (snippet != null) { _spanExpectations.Add(method, result); } return(result); }
private static void Analyzer(SyntaxNodeAnalysisContext context) { if (context.IsGenerated()) { return; } var method = new MethodInformation( "Parse", "System.Net.IPAddress.Parse(string)", args => { if (!(args[0] is string)) { return; } parseMethodInfo.Value.Invoke(null, new[] { args[0].ToString() }); } ); var checker = new MethodChecker(context, Rule); checker.AnalyzeMethod(method); }