Recursive WebRequest.Create()

S

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?
 
V

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
 
S

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
 
V

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top