Not sure if I am explaining this correctly but here goes..

I am working on a .dll that depending on a value determined at startup, will select which method to use next.


At the very beginning of this dll,

private string _Ver = Application.ProductVersion;

Now if _Ver < 2 then use

public List<System.Windows.Forms.Form> Startup()
{
//code here
}

If _Ver > 2 then use

public void Startup()
{
//code here
}

Can this be done?
if so, how?


Steve

It can be done, unfortunately I'm not an expert on it so my help is limited. You need to use the .Net reflection class. You can use this to examine a dll or class at runtime and from there call the right method.
I'm sure Google can supply tutorials now that you know what to look for.

I hope that helps,

Ok, I missed a small detail in this..

You can't have two instances of the method "Startup" in the same class.


Is there a way to rename the Method itself?

If _Ver > 2
then rename

public void Startup()

to

public List<Form> Startup()

and vice versa?

Hmm i not to sure i get what your trying to do...

You will Create a new method.You will pass the _Ver to that Method. Inside the method your logic will check the _Ver and call the correct Startup(). But yes you cannot have the same instances of the method twice.

public class Version
    {
       protected string _version;
       public Version()
       {
           _version = Application.ProductVersion;

           if (_version != "")
           {
               AssignStartUp();
           }
       }

       protected void AssignStartUp()
       {
           if (_version == "2")
           {
               StartUp();
           }
           else
           {
               StatupList();
           }
       }

       protected void StartUp()
       {

       }

       protected List<Form> StatupList()
       {

           return new List<Form>();
       }
    }

Sorry for the late reply.

I have not had a chance to test this yet, but I am still wondering about renaming the Method based on the results of _version? Can this be done?

If you could give one of those a different parameter list, it would work easily -- even if the parameter is bogus.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.