troubleshooting Question

Static methods in c#

Avatar of ksd123
ksd123 asked on
C#.NET ProgrammingASP.NET
3 Comments2 Solutions404 ViewsLast Modified:
Hi experts,

We have a web service that was developed using .net framework 2.0/ VS 2005 and we deploy the service using MSI installer with some custom actions.Now we are upgrading this service installer to vs 2013 using wix  toolset v3.8.Since we have custom actions defined in the Serivice and I am trying to convert the code written in .net  
framework 2.0/ VS 2005 to .net framework 4.5/ VS 2013.

1)I have following method in one of the custom actions
a)
[RunInstaller(true)]
    public partial class Installer1 : System.Configuration.Install.Installer
    {
        
        private string version;
        
        public Installer1()
        {
            InitializeComponent();
        }


        protected override void OnCommitted(IDictionary savedState)
        {
            
            if(Context.Parameters["testversion"]!=null)
            {
                string version = Context.Parameters["testversion"].ToString();
                this.version=version;
            }
            demo();
        }

        public void demo()
        {
            string somevalue = this.version;
        }

    }


In the above OnCommitted method why there is a local variable "version" and later assigned the value using "this.version".We already have global variable "version" and we can simply do like below

b) if(Context.Parameters["testversion"]!=null)
            {
                version = Context.Parameters["testversion"].ToString();
               
            }

1)My question is "Is there any issue with the above code without using "this.version" ?


2) I am converting MSI custom actions to wix custom actions and in this process I have  converted the above code (a) to following code .Basically we have to convert it to static methods

public class CustomActions
 {

      private static string version;

     [CustomAction]
     public static ActionResult OnCommitted(Session session)
      {
         if(session.CustomActionData[]!=null)
      {

	version = session.CustomActionData[].ToString();

      }
      
      demo();   

         return ActionResult.Success;
     }

     public static void demo()
        {
            string somevalue = version;
        }
   
 }


Since we don't have "this" in vs 2013, I have directly assigned golbal variable "version".Is this correct way of converting non-static to static methods or am i breaking anything in the above code.

Thanks in advance
ASKER CERTIFIED SOLUTION
Miguel Oz
Senior Software Engineer
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros