private void AnalyzeCodeBlock(CodeBlockStartAnalysisContext <SyntaxKind> codeBlockStartContext) { if (!codeBlockStartContext.CodeBlock.IsKind(SyntaxKind.MethodDeclaration) && !codeBlockStartContext.CodeBlock.IsKind(SyntaxKind.ConstructorDeclaration)) { return; } IMethodSymbol methodSymbol = codeBlockStartContext.OwningSymbol as IMethodSymbol; if (!(methodSymbol?.Parameters.Length > 0) || methodSymbol.IsOverride || methodSymbol.IsVirtual || methodSymbol.IsEntryPoint() || methodSymbol.ImplementsInterface()) { return; } ParameterTracker tracker = new ParameterTracker(methodSymbol.Parameters); codeBlockStartContext.RegisterCodeBlockEndAction(codeBlockContext => tracker.ReportUnusedParameters(codeBlockContext)); codeBlockStartContext.RegisterSyntaxNodeAction(nodeContext => tracker.TryDiscardReferencedParameter(nodeContext), SyntaxKind.IdentifierName); }
/// <summary> /// This is where the page is initialised and all components get added. /// </summary> /// <param name="sender">The object that sent the request</param> /// <param name="e">Arguments passed in</param> public void Page_Load(object sender, EventArgs e) { // Create the param tracker and request objects for this request _tracker = new ParameterTracker(this); if (WebConfigurationManager.AppSettings["aspneterrors"] == "1") { DoPageLoad(); } else { bool wasExceptionCaught = false; try { DoPageLoad(); } catch (Exception ex) { if (ex.GetType() == typeof(HttpException) && ex.Message == _botNotAllowedMessage) { throw; } wasExceptionCaught = true; if (Diagnostics != null) { Diagnostics.WriteExceptionToLog(ex); } } // Initialise an error page here if we don't have one already to stop a further error // masking the real one. if (_page == null) { if (_viewingUser == null) { _viewingUser = new User(this); } _page = new WholePage(this); _page.InitialisePage("ERROR"); } if (wasExceptionCaught && _page != null) { XmlNode h2g2 = _page.RootElement.FirstChild; XmlNode errornode = _page.AddTextTag(h2g2, "ERROR", "An unknown error has occurred"); _page.AddAttribute(errornode, "REQUESTID", _requestId.ToString()); _page.AddAttribute(errornode, "TIME", DateTime.Now.ToString("dd MMMM yyyy, HH:mm:ss")); string originalType = h2g2.Attributes["TYPE"].InnerText; _page.AddAttribute(errornode, "ORIGINALPAGETYPE", originalType); // This will fail if there's no TYPE attribute - but that's a fatal bug at this point anyway h2g2.Attributes["TYPE"].InnerText = "ERROR"; } } }