Home All Groups Group Topic Archive Search About

Recursive WebRequest.Create()

Author
5 May 2006 10:04 AM
Sathyaish
The WebRequest class implements IWebRequestCreate and hence, a method
Create.

This method has two other overloads, one of which is a private method.
Here's how it looks:

public static WebRequest Create(string requestUriString)
public static WebRequest Create(Uri requestUri)
private static WebRequest Create(Uri requestUri, bool useUriBase)


Both the public overloads with a single argument internally call the
private overload with the second parameter as false. The implementation
of the private method is given below:


private static WebRequest Create(Uri requestUri, bool useUriBase)
{
      string text1;
      WebRequestPrefixElement element1 = null;
      bool flag1 = false;
      if (!useUriBase)
      {
            text1 = requestUri.AbsoluteUri;
      }
      else
      {
            text1 = requestUri.Scheme + ':';
      }
      int num1 = text1.Length;
      ArrayList list1 = WebRequest.PrefixList;
      for (int num2 = 0; num2 < list1.Count; num2++)
      {
            element1 = (WebRequestPrefixElement) list1[num2];
            if ((num1 >= element1.Prefix.Length) &&
(string.Compare(element1.Prefix, 0, text1, 0, element1.Prefix.Length,
true, CultureInfo.InvariantCulture) == 0))
            {
                  flag1 = true;
                  break;
            }
      }
      if (!flag1)
      {
            throw new
NotSupportedException(SR.GetString("net_unknown_prefix"));
      }
      return element1.Creator.Create(requestUri);
}


I was surprised to see the last statement of this private overload
calling one of the other public overloads. Isn't this recursive, or am
I missing something here?

Author
5 May 2006 1:49 PM
Vadym Stetsyak
Hello, Sathyaish!

S> {
  S>       return element1.Creator.Create(requestUri);
S> }

You mean that this statement will fall in recursion?
Why do you think so?

WebRequest.Create(...), creates specific request objects. It creates them using WebRequestPrefixElement.
I do not see any recursion here....

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Author
5 May 2006 3:45 PM
Sathyaish
Hi Vadym,

Thanks for replying.

I was wrong in thinking so and I realized this by writing out my
thoughts in great detail in these posts. It is a wonder that writing
your thoughts down in a detailed manner can reveal the cause of your
own confusion and give you the answer to your problem.

Here're the links for your reference:

http://discuss.joelonsoftware.com/default.asp?dotnet.12.339841.6

http://channel9.msdn.com/ShowPost.aspx?PostID=189550

Thanks again.
Author
5 May 2006 3:49 PM
Sathyaish
Hi again, Vadym!


On visiting your blog link, I recognize that I'd only followed a few
links that led to your blog only a few weeks ago. I think I know you
from elsewhere too. Do you post on JoS/CoT/Channel 9?


Regards,
Sathyaish
Author
5 May 2006 3:55 PM
Vadym Stetsyak
Hello, Sathyaish!

S> On visiting your blog link, I recognize that I'd only followed a few
S> links that led to your blog only a few weeks ago. I think I know you
S> from elsewhere too. Do you post on JoS/CoT/Channel 9?

Actually no. Maybe some search engines or people mentioned the link to the blog.
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com