mscorlib(4.0.0.0) API with additions
XmlUrlResolver.cs
1 using System.IO;
2 using System.Net;
3 using System.Net.Cache;
5 using System.Threading;
7 
8 namespace System.Xml
9 {
11  public class XmlUrlResolver : XmlResolver
12  {
13  private static object s_DownloadManager;
14 
15  private ICredentials _credentials;
16 
17  private IWebProxy _proxy;
18 
19  private RequestCachePolicy _cachePolicy;
20 
21  private static XmlDownloadManager DownloadManager
22  {
23  get
24  {
25  if (s_DownloadManager == null)
26  {
27  object value = new XmlDownloadManager();
28  Interlocked.CompareExchange<object>(ref s_DownloadManager, value, (object)null);
29  }
30  return (XmlDownloadManager)s_DownloadManager;
31  }
32  }
33 
36  public override ICredentials Credentials
37  {
38  set
39  {
40  _credentials = value;
41  }
42  }
43 
46  public IWebProxy Proxy
47  {
48  set
49  {
50  _proxy = value;
51  }
52  }
53 
57  {
58  set
59  {
60  _cachePolicy = value;
61  }
62  }
63 
75  public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
76  {
77  if (ofObjectToReturn == null || ofObjectToReturn == typeof(Stream) || ofObjectToReturn == typeof(object))
78  {
79  return DownloadManager.GetStream(absoluteUri, _credentials, _proxy, _cachePolicy);
80  }
81  throw new XmlException("Xml_UnsupportedClass", string.Empty);
82  }
83 
90  [PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
91  public override Uri ResolveUri(Uri baseUri, string relativeUri)
92  {
93  return base.ResolveUri(baseUri, relativeUri);
94  }
95 
101  public override async Task<object> GetEntityAsync(Uri absoluteUri, string role, Type ofObjectToReturn)
102  {
103  if (ofObjectToReturn == null || ofObjectToReturn == typeof(Stream) || ofObjectToReturn == typeof(object))
104  {
105  return await DownloadManager.GetStreamAsync(absoluteUri, _credentials, _proxy, _cachePolicy).ConfigureAwait(continueOnCapturedContext: false);
106  }
107  throw new XmlException("Xml_UnsupportedClass", string.Empty);
108  }
109  }
110 }
IWebProxy Proxy
Gets or sets the network proxy for the underlying T:System.Net.WebRequest object.
Definition: __Canon.cs:3
override async Task< object > GetEntityAsync(Uri absoluteUri, string role, Type ofObjectToReturn)
Asynchronously maps a URI to an object that contains the actual resource.
Resolves external XML resources named by a Uniform Resource Identifier (URI).
Definition: XmlResolver.cs:8
RequestCachePolicy CachePolicy
Gets or sets the cache policy for the underlying T:System.Net.WebRequest object.
SecurityAction
Specifies the security actions that can be performed using declarative security.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
Resolves external XML resources named by a Uniform Resource Identifier (URI).
override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
Maps a URI to an object that contains the actual resource.
Provides the base authentication interface for retrieving credentials for Web client authentication.
Definition: ICredentials.cs:5
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Defines an application's caching requirements for resources obtained by using T:System....
Returns detailed information about the last exception.
Definition: XmlException.cs:12
override ICredentials Credentials
Sets credentials used to authenticate web requests.
Provides the base interface for implementation of proxy access for the T:System.Net....
Definition: IWebProxy.cs:5
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Definition: Uri.cs:19
override Uri ResolveUri(Uri baseUri, string relativeUri)
Resolves the absolute URI from the base and relative URIs.
Provides atomic operations for variables that are shared by multiple threads.
Definition: Interlocked.cs:10
Represents an asynchronous operation that can return a value.
Definition: Task.cs:18
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
Definition: Stream.cs:16