How do I know if the “Analyze generated files” setting has been checked by the user?

May 11, 2010 at 8:39 AM


How do I know if the “Analyze generated files” setting has been checked by the user?


I would like to get this attribute in runtime to customize a rule.

Can anyone help?

May 11, 2010 at 2:54 PM

Hey, the source code is already open, isn't it?

See SkipAnalysisForDocument method.


Best regards,
Oleg Shuruev 

May 12, 2010 at 3:39 AM

Hi Shuruev,


I tried this:

internal static bool CheckSomeRule(CsElement elem, SourceAnalyzer analyzer)


          BooleanProperty val = analyzer.GetSetting( elem.Document.Settings, "AnalyzeGeneratedFiles") as BooleanProperty;



And it returned null, while I already have the “Analyze generated files” as checked.

May 12, 2010 at 5:18 AM

First of all,
"AnalyzeGeneratedFiles" is a setting that belongs to parser (CsParser), not to analyzer.

Any "GetSetting" call may return null if the setting is not set at this level. In this case you should use the inherited value of your setting.
You can get it by reading default value from corresponding descriptor (use PropertyDescriptors collection).

Best regards,
Oleg Shuruev

May 12, 2010 at 6:13 AM

No, check this:


    /// <summary>
    /// C# code analyzer
    /// </summary>
    public class CustomizedAnalyzer : SourceAnalyzer
        /// <summary>
        /// Analyze a C# document
        /// </summary>
        /// <param name="document">input code document</param>
        public override void AnalyzeDocument(CodeDocument document)
            Param.RequireNotNull(document, "document");
            BooleanProperty val = this.GetSetting(document.Settings,
                "AnalyzeGeneratedFiles") as BooleanProperty;

            AddInPropertyCollection[] properties = document.Settings.ParserSettings.ToArray<AddInPropertyCollection>();
            string[] strs = properties[0].AddIn.PropertyDescriptors.PropertyNames.ToArray();
            // ...


Here, val = null,

but in strs, it is

str[0] = "AnalyzeDesignerFiles";

str[1] = "AnalyzeGeneratedFiles";

str[2] = "Enabled";

str[3] = "FileMustBeReadable#enabled";

str[4] = "ExceptionOccurred#Enabled";

str[5] = "SyntaxException#Enabled";

 The property exists, but when I try get it, I received null.

Where did I go wrong?

May 12, 2010 at 6:26 AM


Hey, this one works.:

BooleanProperty val = this.Parser.GetSetting(document.Settings, "AnalyzeGeneratedFiles") as BooleanProperty;


Thanks very much for your answer, very helpful. :)