Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Xml / System / Xml / XmlResolver.cs
blob2245d76d20a61ddd1a3a64fc61bca0afc169a2b5
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlResolver.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 namespace System.Xml
10 using System;
11 using System.IO;
12 using System.Text;
13 using System.Security;
14 using System.Security.Permissions;
15 #if !SILVERLIGHT
16 using System.Net;
17 using System.Threading.Tasks;
18 #endif
19 using System.Runtime.Versioning;
21 /// <include file='doc\XmlResolver.uex' path='docs/doc[@for="XmlResolver"]/*' />
22 /// <devdoc>
23 /// <para>Resolves external XML resources named by a Uniform
24 /// Resource Identifier (URI). This class is <see langword='abstract'/>
25 /// .</para>
26 /// </devdoc>
27 public abstract partial class XmlResolver {
28 /// <include file='doc\XmlResolver.uex' path='docs/doc[@for="XmlResolver.GetEntity1"]/*' />
29 /// <devdoc>
30 /// <para>Maps a
31 /// URI to an Object containing the actual resource.</para>
32 /// </devdoc>
34 public abstract Object GetEntity(Uri absoluteUri,
35 string role,
36 Type ofObjectToReturn);
40 /// <include file='doc\XmlResolver.uex' path='docs/doc[@for="XmlResolver.ResolveUri"]/*' />
41 /// <devdoc>
42 /// <para>[To be supplied.]</para>
43 /// </devdoc>
44 #if !SILVERLIGHT
45 [ResourceExposure(ResourceScope.Machine)]
46 [ResourceConsumption(ResourceScope.Machine)]
47 #endif
48 public virtual Uri ResolveUri(Uri baseUri, string relativeUri) {
49 if ( baseUri == null || ( !baseUri.IsAbsoluteUri && baseUri.OriginalString.Length == 0 ) ) {
50 Uri uri = new Uri( relativeUri, UriKind.RelativeOrAbsolute );
51 #if !SILVERLIGHT // Path.GetFullPath is SecurityCritical
52 if ( !uri.IsAbsoluteUri && uri.OriginalString.Length > 0 ) {
53 uri = new Uri( Path.GetFullPath( relativeUri ) );
55 #endif
56 return uri;
58 else {
59 if (relativeUri == null || relativeUri.Length == 0) {
60 return baseUri;
62 // relative base Uri
63 if ( !baseUri.IsAbsoluteUri ) {
64 #if SILVERLIGHT
65 // create temporary base for the relative URIs
66 Uri tmpBaseUri = new Uri("tmp:///");
68 // create absolute base URI with the temporary base
69 Uri absBaseUri = new Uri(tmpBaseUri, baseUri.OriginalString);
71 // resolve the relative Uri into a new absolute URI
72 Uri resolvedAbsUri = new Uri(absBaseUri, relativeUri);
74 // make it relative by removing temporary base
75 Uri resolvedRelUri = tmpBaseUri.MakeRelativeUri(resolvedAbsUri);
77 return resolvedRelUri;
78 #else
79 throw new NotSupportedException(Res.GetString(Res.Xml_RelativeUriNotSupported));
80 #endif
82 return new Uri( baseUri, relativeUri );
86 #if !SILVERLIGHT
87 //UE attension
88 /// <include file='doc\XmlResolver.uex' path='docs/doc[@for="XmlResolver.Credentials"]/*' />
89 /// <devdoc>
90 /// <para>[To be supplied.]</para>
91 /// </devdoc>
92 public virtual ICredentials Credentials {
93 set { }
95 #endif
97 public virtual bool SupportsType(Uri absoluteUri, Type type) {
98 if (absoluteUri == null) {
99 throw new ArgumentNullException("absoluteUri");
101 if (type == null || type == typeof(Stream)) {
102 return true;
104 return false;