Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return .f. in Init Fox Equivalent
Message
 
À
12/01/2006 13:58:18
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01085894
Message ID:
01086256
Vues:
13
Bonnie,
That is pretty slick. Kudos to whoever came up with it and kudos to you for sharing ;)

Einar


>Scott,
>
>Einar's suggestion was good, but the only problem I had with it is that throwing/catching exceptions is expensive. I decided to try and find another way. (To be honest, I didn't come up with this myself, I posted a question on another forum <g>). Here's the suggestion:
>
>public class TestIt
>{
>	private TestIt()
>	{
>	}
>
>	public static TestIt Create()
>	{
>		bool ItsOK = true;
>		// code here to determine whether to instantiate
>
>		if (ItsOK)
>			return new TestIt();
>		else
>			return null;
>	}
>}
>
>Notice the static method. Then, to instantiate the class:
>
>TestIt oTest = MyNameSpace.TestIt.Create();
>if (oTest == null)
>	MessageBox.Show("Not Instantiated");
>else
>	MessageBox.Show("Instantiated");
>
>
>~~Bonnie
>
>
>>That is just what I need to know. Thanks to both you and Hilmar.
>>
>>I am creating a class that will be used for Word automation, If Word isn't installed or
>>it is an older version I want to message the user and not create the object. Is there another way that this
>>should be handled in .Net (I am a newbie).
>>
>>Thanks Again
>>Scott
>>
>>>Scott,
>>>That is what I thought but I wasn't 100% sure.
>>>
>>>Throwing an exception from within the constructor will cause the object not to be instantiated.
>>>
>>>throw new Exception("I don't want this object to be instantiated.");
>>>
>>>
>>>If you explain a little further what you want then we might be able to find more ways to skin the cat.
>>>
>>>Einar
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform