Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling Overloaded Constructors
Message
De
26/01/2006 00:40:10
 
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01090151
Message ID:
01090395
Vues:
8
This message has been marked as the solution to the initial question of the thread.
Chad,

AFAIK, you can't change that order, at least not in 1.1 (and I doubt if it's different in 2.0, but I don't know for sure). I'd rewrite the class this way:
        private bool LogInit = true;

        public jsEventLog(bool logInit) 
        {
            this.LogInit = logInit;
            this.FinishConstructor();
        }

        public jsEventLog(string source) 
        {
            this.Source = source;
            this.FinishConstructor();
        }

        public void FinishConstructor()
        {
            if (this.LogInit)
            {
                this.WriteEntry("Event log object has been initialized.");
            }
        }
~~Bonnie



>Hi all,
>
>Here's a snippet from a class I'm writing:
>
>        public jsEventLog(bool logInit) : this()
>        {
>            if (logInit)
>            {
>                this.WriteEntry("Event log object has been initialized.");
>            }
>        }
>
>        public jsEventLog(string source) : this(true)
>        {
>            this.Source = source;
>        }
>
>The idea is to be able to instantiate this class with a string and have it log an initialized message automatically. The WriteEntry method has several overloads, and using the one above defaults the source to the this.Source value. The problem is that when the 2nd constructor is called (by instantiation), it calls the 1st constructor before it runs the code within the 2nd constructor. Is there a way to change that order or do I have to rewrite my methods in such a way that all my methods will work with that ordering?
>
>TIA,
>Chad
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform