SubMain - CodeIt.Right The First Time!

/Community

Support Community for SubMain Products
 Home Products Services Download Purchase Support
in Search
 
Home Forums Blogs Tutorials/CIR Tutorials/GD Downloads
Welcome to SubMain Community Sign in | Join | Help

check method is resetting Rule class fields after returning true

Last post 11-05-2014, 4:18 AM by Misha Zhutov (SubMain). 4 replies.
Sort Posts: Previous Next
  •  11-04-2014, 10:40 PM 4006

    check method is resetting Rule class fields after returning true

    I am making a custom rules to check duplication of method names in multiple class. My logic is that I am using a global string list to store methods names. Target = RuleTargets.Method. My code is given below:

     

     

            private const RuleScopes SCOPES = RuleScopes.Public | RuleScopes.ProtectedInternal | RuleScopes.Private | RuleScopes.Abstract | RuleScopes.Sealed | RuleScopes.Readonly | RuleScopes.Virtual | RuleScopes.Override | RuleScopes.Unsafe | RuleScopes.Const | RuleScopes.Volatile | RuleScopes.WriteOnly | RuleScopes.WithEvents;

            private const RuleTargets AVAILABLE_TARGETS = RuleTargets.Method;

            private System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>() { };  // this list stores method names 

            public override bool Check(IElementInfo element)

            {

                //SubMain.Core.ExceptionHandling.UnhandledExceptionManager.LogHandler("list:", "arauflog.txt");

                //foreach (string s in list)

                //{

                  //  SubMain.Core.ExceptionHandling.UnhandledExceptionManager.LogHandler(s, "arauflog.txt");

                //}

                IMethodInfo minfo = element as IMethodInfo;

                if (list.Contains(minfo.DisplayName))

                {

                  //  SubMain.Core.ExceptionHandling.UnhandledExceptionManager.LogHandler(minfo.DisplayName+" already exists", "arauflog.txt");

                    //SubMain.Core.ExceptionHandling.UnhandledExceptionManager.LogHandler("list before returning true:", "arauflog.txt");

                    //foreach (string s in list)

                    //{

                      //  SubMain.Core.ExceptionHandling.UnhandledExceptionManager.LogHandler(s, "arauflog.txt");

                    //}

                    return true; //after returning true, list becomes empty

                }

                list.Add(minfo.DisplayName);

                //SubMain.Core.ExceptionHandling.UnhandledExceptionManager.LogHandler(minfo.DisplayName+" added to list", "arauflog.txt");

                return false; //returning false doesn't reset list

     

            } 

     

    Problem is that check method is resetting my list after returning true. Please fix this bug

    Filed under: , ,
  •  11-05-2014, 3:24 AM 4007 in reply to 4006

    Re: check method is resetting Rule class fields after returning true

    Setting list to static temporarily resolved my problem. But now I have to restart visual studio to reset list before running analysis again. Can I somehow reset static variables before running analysis ?
  •  11-05-2014, 3:31 AM 4009 in reply to 4007

    Re: check method is resetting Rule class fields after returning true

    Hi,

    I replied on your question in another thread. Basically, the rule should not store shared data between rule. Use a separate class for that.

     


    Thank you,
    Misha Zhutov
    http://submain.com - .NET Developer Tools | Microsoft VB MVP
  •  11-05-2014, 3:49 AM 4010 in reply to 4006

    Re: check method is resetting Rule class fields after returning true

    Setting list to static temporarily resolved my problem. But now I have to restart visual studio to reset list before running analysis again. Can I somehow reset static variables before running analysis ? It should automatically reset everytime when analysis starts
  •  11-05-2014, 4:18 AM 4012 in reply to 4010

    Re: check method is resetting Rule class fields after returning true

    That's good question, thanks. Actually, there is no such event (when Analysis starts). All our rules are not shared any data.

    Instead, all parsing data is stored and can be used by all the rules.

    Try to set target to Method, run GetProjectMethods(minfo.ProjectFile.Project)

    and search for the same method name in the list.

    Is it work for you?

    We will add such an event in our TODO list.

     


    Thank you,
    Misha Zhutov
    http://submain.com - .NET Developer Tools | Microsoft VB MVP
View as RSS news feed in XML
 
     
 
Home |  Products |  Services |  Download |  Purchase |  Support |  Community |  About Us |