XmlUrlResolver.GetEntity(Uri, String, Type) Metoda

Definice

Mapuje identifikátor URI na objekt, který obsahuje skutečný prostředek.

public:
 override System::Object ^ GetEntity(Uri ^ absoluteUri, System::String ^ role, Type ^ ofObjectToReturn);
public override object? GetEntity(Uri absoluteUri, string? role, Type? ofObjectToReturn);
public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn);
override this.GetEntity : Uri * string * Type -> obj
Public Overrides Function GetEntity (absoluteUri As Uri, role As String, ofObjectToReturn As Type) As Object

Parametry

absoluteUri
Uri

Identifikátor URI vrácený z ResolveUri(Uri, String).

role
String

V současné době se nepoužívá.

ofObjectToReturn
Type

Typ objektu, který se má vrátit. Aktuální implementace vrací Stream pouze objekty.

Návraty

Objekt datového proudu nebo null pokud je zadán jiný typ než datový proud.

Výjimky

ofObjectToReturn null není ani Stream typ.

Zadaný identifikátor URI není absolutní identifikátor URI.

absoluteUri je null.

Došlo k chybě za běhu (například přerušené připojení k serveru).

Příklady

Následující příklad ukazuje metody GetEntity a ResolveUri metody.

using System;
using System.IO;
using System.Xml;

 public class Sample
 {

   public static void Main()
   {
       XmlUrlResolver resolver = new XmlUrlResolver();

       Uri baseUri = new Uri ("http://servername/tmp/test.xsl");

       Uri fulluri=resolver.ResolveUri(baseUri, "includefile.xsl");

       // Get a stream object containing the XSL file
       Stream s=(Stream)resolver.GetEntity(fulluri, null, typeof(Stream));

       // Read the stream object displaying the contents of the XSL file
       XmlTextReader reader = new XmlTextReader(s);
       while (reader.Read())
       {
          Console.WriteLine(reader.ReadOuterXml());
       }
   }
}
Imports System.IO
Imports System.Xml

Public Class Sample
    
  Public Shared Sub Main()

     Dim resolver As New XmlUrlResolver()
     Dim baseUri As New Uri("http://servername/tmp/test.xsl")
     Dim fulluri As Uri = resolver.ResolveUri(baseUri, "includefile.xsl")
            
     ' Get a stream object containing the XSL file
     Dim s As Stream = CType(resolver.GetEntity(fulluri, Nothing, GetType(Stream)), Stream)
            
     ' Read the stream object displaying the contents of the XSL file
     Dim reader As New XmlTextReader(s)
     While reader.Read()
        Console.WriteLine(reader.ReadOuterXml())
     End While
        
  End Sub
End Class

Poznámky

Tato metoda se používá, když volající chce mapovat daný identifikátor URI na objekt, který obsahuje prostředek, který představuje identifikátor URI.

Asynchronní verzi této metody naleznete v tématu GetEntityAsync.

Important

Vaše aplikace může zmírnit hrozby GetEntity pro odepření služby do metody implementací IStreamu IStream , aby omezila počet přečtených bajtů. To pomáhá chránit před situacemi, kdy se škodlivý kód pokusí předat do metody nekonečný proud bajtů GetEntity .

Platí pro

Viz také