Federico, You are right but unfortunately that doesn't help. The WebRequest system checks registered prefixes before instantiating the appropriate classes (it has to). In order for your suggestion to work, the code needs to refer to my derivative somewhere to call the constructor. From what I can tell, there are only a limited number of places where code can be defined. An attribute (haven't tried this approach), user written classes, and the classes in my library.
The user should only have to write the following so that leaves user written code out of consideration. WebRequest wr = WebRequest.Create("prot://host/url") I havne't found a way to have code inside my library automatically called. In the old C++ days, I would have used a globally defined object with a constructor that performed the call. Are there any assembly level startup routines like the old DllInit stuff? What do you think about the attribute approach? Reggie > -----Original Message----- > From: dotnet discussion [mailto:[EMAIL PROTECTED]] On Behalf Of > Federico Raggi > Sent: Friday, May 24, 2002 11:03 AM > To: [EMAIL PROTECTED] > Subject: Re: [DOTNET] Automatically executing code > > Reggie: > You don't need to instantiate the class to initialize its static > members. You just need to use some of its members in your code. The > static constructor is called when the class is loaded and it will be > loaded only if it's needed by your call. > > Here is a small sample that initializes a seed using the Random > class. If you comment the DoSomething() method call in Main, it won't > load StaticClass nor execute its static constructor. > > using System; > > namespace DotNetList.FedeR > { > class StaticClass > { > static float seed; > > static StaticClass() > { > Console.WriteLine("StaticClass Initializing"); > Random r = new Random(); > seed = r.Next(); > } > > public static void DoSomething() > { > Console.WriteLine("DoingSomething: Seed="+seed); > } > } > > class myApp > { > static void Main() > { > Console.WriteLine("Entering Main"); > // If you comment this line, constructor won't > be called > StaticClass.DoSomething(); > } > } > } > > Federico Raggi > Latam Developers Initiative Manager > Microsoft > > Phone: (954)489-4862 > Mobile: (954)465-4862 > > > -----Original Message----- > > From: Reggie Burnett [mailto:[EMAIL PROTECTED]] > > Sent: Friday, May 24, 2002 10:58 AM > > To: [EMAIL PROTECTED] > > Subject: Re: [DOTNET] Automatically executing code > > > > That's what I thought. I tried using a static constructor but you have > > to explicitly create an object to get it to fire. I'm looking for > > something that will automatically run the code to register my prefix > > without the user of the lib having to do anything. Their first line > of > > code should be something like > > > > Wr = WebRequest.Create("blah blah url"); > > > > Is there something at the assembly level or an attribute that I could > > use to automatically fire some code at app startup? > > > > Reggie > > > > > -----Original Message----- > > > From: dotnet discussion [mailto:[EMAIL PROTECTED]] On > Behalf > > Of > > > Richard Birkby > > > Sent: Friday, May 24, 2002 4:21 AM > > > To: [EMAIL PROTECTED] > > > Subject: Re: [DOTNET] Automatically executing code > > > > > > Can you use a static constructor somewhere? > > > System.Net registers HTTP, HTTPS and FILE the first time the prefix > > list > > > is > > > used *. > > > > > > > > > Richard > > > * It uses a double check locking idiom without a volatile keyword... > > > > > > > -----Original Message----- > > > > From: dotnet discussion [mailto:[EMAIL PROTECTED]]On > Behalf > > Of > > > > Reggie Burnett > > > > Sent: 24 May 2002 01:17 > > > > To: [EMAIL PROTECTED] > > > > Subject: [DOTNET] Automatically executing code > > > > > > > > > > > > I'm implementing a webrequest/webresponse pair and the docs say > that > > you > > > > have to call WebRequest.RegisterPrefix to register your creator > > object > > > > with that prefix. What is the best way to make that call > > automatically > > > > without the user of the library needing to explicitly do that? > > > > > > > > Reggie > > > > > > > > You can read messages from the DOTNET archive, unsubscribe from > > DOTNET, > > > or > > > > subscribe to other DevelopMentor lists at > > http://discuss.develop.com. > > > > > > You can read messages from the DOTNET archive, unsubscribe from > > DOTNET, or > > > subscribe to other DevelopMentor lists at > http://discuss.develop.com. > > > > You can read messages from the DOTNET archive, unsubscribe from > DOTNET, or > > subscribe to other DevelopMentor lists at http://discuss.develop.com. > > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.