Disabling/Fixing Code Analysis warnings from .Designer.cs files

后端 未结 4 1420
忘了有多久
忘了有多久 2021-02-13 14:44

I am using DataVisualization.Charting.Chart extensively, and for the most part it is working. However, I\'ve been running Code Analysis frequently, and have all my

4条回答
  •  暖寄归人
    2021-02-13 15:33

    I know I'm late to this but here goes.

    I'm guessing these warnings are all emitted for code within the InitializeComponent method? If so then have you considered modifying the template files located in Common7\IDE\ItemTemplates folder? You could add the GeneratedCode attribute on the method in those. Since the attribute will be set only on it, all your other code within the same class will still get checked by code analysis.

    Here's an example for Form designer file:

    namespace $rootnamespace$
    {
        partial class $safeitemrootname$
        {
            /// 
            /// Required designer variable.
            /// 
            private System.ComponentModel.IContainer components = null;
    
            /// 
            /// Clean up any resources being used.
            /// 
            /// true if managed resources should be disposed; otherwise, false.
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            #region Windows Form Designer generated code
    
            /// 
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// 
            [System.CodeDom.Compiler.GeneratedCode("Windows Form Designer generated code", "1.0.0.0"), System.Diagnostics.DebuggerNonUserCode()]
            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.Text = "$safeitemrootname$";
            }
    
            #endregion
        }
    }
    

提交回复
热议问题