[Mono-devel-list] small fix

Konstantin Triger kostat at mainsoft.com
Tue Mar 29 10:56:18 EST 2005


Hello Eno,

I looked into XmlUrlResolver and found this code:

        // Methods
        public override object GetEntity (Uri absoluteUri, string role, 
Type ofObjectToReturn)
        {
            if (ofObjectToReturn == null)
                ofObjectToReturn = typeof (Stream);
            if (ofObjectToReturn != typeof (Stream))
                throw new XmlException ("This object type is not 
supported.");

            if (absoluteUri.Scheme == "file") {
                if (absoluteUri.AbsolutePath == String.Empty)
                    throw new ArgumentException ("uri must be 
absolute.", "absoluteUri");
                return new FileStream (UnescapeRelativeUriBody 
(absoluteUri.LocalPath), FileMode.Open, FileAccess.Read, FileShare.Read);
            }

            // (MS documentation says) parameter role isn't used yet.
            Stream s = null;
            using (s) {
                WebClient wc = new WebClient ();
                wc.Credentials = credential;
                byte [] data = wc.DownloadData (absoluteUri.ToString ());
                wc.Dispose ();
                return new MemoryStream (data, 0, data.Length);
             }
        }

Don't you think that the highlighted part should be replcaed with that 
following one (here we return the underlying reponse's stream instead of 
allocating a new one):

            WebRequest req = WebRequest.Create(absoluteUri);
            if (credential != null)
                req.Credentials = credential;

            return req.GetResponse().GetResponseStream();

-- 
Regards,
Konstantin Triger




More information about the Mono-devel-list mailing list