>That is pretty slick. Kudos to whoever came up with it and kudos to you for sharing ;)<Yeah, Einar ... I thought it was pretty kewl too. The guy's name is David Banister over on the MSDN forums. This link might get you there, in case you're interested ...
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=200718&SiteID=1~~Bonnie
>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