Type.FindInterfaces(TypeFilter, Object) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
public:
virtual cli::array <Type ^> ^ FindInterfaces(System::Reflection::TypeFilter ^ filter, System::Object ^ filterCriteria);
public virtual Type[] FindInterfaces (System.Reflection.TypeFilter filter, object? filterCriteria);
public virtual Type[] FindInterfaces (System.Reflection.TypeFilter filter, object filterCriteria);
abstract member FindInterfaces : System.Reflection.TypeFilter * obj -> Type[]
override this.FindInterfaces : System.Reflection.TypeFilter * obj -> Type[]
Public Overridable Function FindInterfaces (filter As TypeFilter, filterCriteria As Object) As Type()
매개 변수
- filter
- TypeFilter
인터페이스를 filterCriteria에 대해 비교하는 대리자입니다.
- filterCriteria
- Object
반환되는 배열에 인터페이스가 포함되어야 하는지를 결정하는 검색 조건입니다.
반환
- Type[]
현재 Type에 의해 구현되거나 상속된 인터페이스의 필터링된 목록을 나타내는 Type 개체 배열이거나, 필터와 일치하는 인터페이스 중에서 현재 Type에 의해 구현되거나 상속된 인터페이스가 없는 경우에는 빈 배열입니다.
구현
예외
filter이(가) null인 경우
정적 이니셜라이저가 호출되고 예외를 발생합니다.
예제
다음 예제에서는 지정 된 형식에 의해 구현 되거나 상속 된 지정 된 인터페이스를 찾은 다음 인터페이스 이름을 표시 합니다.
#using <system.xml.dll>
using namespace System;
using namespace System::Xml;
using namespace System::Reflection;
public ref class MyFindInterfacesSample
{
public:
static bool MyInterfaceFilter(Type^ typeObj, Object^ criteriaObj)
{
if(typeObj->ToString()->Equals(criteriaObj->ToString()))
return true;
else
return false;
}
};
int main()
{
try
{
XmlDocument^ myXMLDoc = gcnew XmlDocument;
myXMLDoc->LoadXml("<book genre='novel' ISBN='1-861001-57-5'>"
+ "<title>Pride And Prejudice</title> </book>");
Type^ myType = myXMLDoc->GetType();
// Specify the TypeFilter delegate that compares the interfaces
// against filter criteria.
TypeFilter^ myFilter = gcnew TypeFilter(
MyFindInterfacesSample::MyInterfaceFilter);
array<String^>^myInterfaceList = {"System.Collections.IEnumerable",
"System.Collections.ICollection"};
for(int index = 0; index < myInterfaceList->Length; index++)
{
array<Type^>^myInterfaces = myType->FindInterfaces(
myFilter, myInterfaceList[index]);
if(myInterfaces->Length > 0)
{
Console::WriteLine("\n{0} implements the interface {1}.",
myType, myInterfaceList[index]);
for(int j = 0; j < myInterfaces->Length; j++)
Console::WriteLine("Interfaces supported: {0}.",
myInterfaces[j]);
}
else
Console::WriteLine(
"\n{0} does not implement the interface {1}.",
myType, myInterfaceList[index]);
}
}
catch(ArgumentNullException^ e)
{
Console::WriteLine("ArgumentNullException: {0}", e->Message);
}
catch(TargetInvocationException^ e)
{
Console::WriteLine("TargetInvocationException: {0}", e->Message);
}
catch(Exception^ e)
{
Console::WriteLine("Exception: {0}", e->Message);
}
}
using System;
using System.Xml;
using System.Reflection;
public class MyFindInterfacesSample
{
public static void Main()
{
try
{
XmlDocument myXMLDoc = new XmlDocument();
myXMLDoc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" + "</book>");
Type myType = myXMLDoc.GetType();
// Specify the TypeFilter delegate that compares the
// interfaces against filter criteria.
TypeFilter myFilter = new TypeFilter(MyInterfaceFilter);
String[] myInterfaceList = new String[2]
{"System.Collections.IEnumerable",
"System.Collections.ICollection"};
for(int index=0; index < myInterfaceList.Length; index++)
{
Type[] myInterfaces = myType.FindInterfaces(myFilter,
myInterfaceList[index]);
if (myInterfaces.Length > 0)
{
Console.WriteLine("\n{0} implements the interface {1}.",
myType, myInterfaceList[index]);
for(int j =0;j < myInterfaces.Length;j++)
Console.WriteLine("Interfaces supported: {0}.",
myInterfaces[j].ToString());
}
else
Console.WriteLine(
"\n{0} does not implement the interface {1}.",
myType,myInterfaceList[index]);
}
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: " + e.Message);
}
catch(TargetInvocationException e)
{
Console.WriteLine("TargetInvocationException: " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
}
public static bool MyInterfaceFilter(Type typeObj,Object criteriaObj)
{
if(typeObj.ToString() == criteriaObj.ToString())
return true;
else
return false;
}
}
Imports System.Xml
Imports System.Reflection
Public Class MyFindInterfacesSample
Public Shared Sub Main()
Try
Dim myXMLDoc As New XmlDocument()
myXMLDoc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" _
& "<title>Pride And Prejudice</title>" & "</book>")
Dim myType As Type = myXMLDoc.GetType()
' Specify the TypeFilter delegate that compares the
' interfaces against filter criteria.
Dim myFilter As New TypeFilter(AddressOf MyInterfaceFilter)
Dim myInterfaceList() As String = _
{"System.Collections.IEnumerable", _
"System.Collections.ICollection"}
Dim index As Integer
For index = 0 To myInterfaceList.Length - 1
Dim myInterfaces As Type() = _
myType.FindInterfaces(myFilter, myInterfaceList(index))
If myInterfaces.Length > 0 Then
Console.WriteLine(ControlChars.Cr & _
"{0} implements the interface {1}.", _
myType, myInterfaceList(index))
Dim j As Integer
For j = 0 To myInterfaces.Length - 1
Console.WriteLine("Interfaces supported: {0}", _
myInterfaces(j).ToString())
Next j
Else
Console.WriteLine(ControlChars.Cr & _
"{0} does not implement the interface {1}.", _
myType, myInterfaceList(index))
End If
Next index
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException: " & e.Message)
Catch e As TargetInvocationException
Console.WriteLine("TargetInvocationException: " & e.Message)
Catch e As Exception
Console.WriteLine("Exception: " & e.Message)
End Try
End Sub
Public Shared Function MyInterfaceFilter(ByVal typeObj As Type, _
ByVal criteriaObj As [Object]) As Boolean
If typeObj.ToString() = criteriaObj.ToString() Then
Return True
Else
Return False
End If
End Function 'MyInterfaceFilter
End Class
설명
이 메서드는 파생 클래스에 의해 재정의 될 수 있습니다.
Module.FilterTypeName Module.FilterTypeNameIgnoreCase 클래스에서 제공 하는 및 대리자를 대리자 대신 사용할 수도 System.Reflection.Module 있습니다 System.Reflection.TypeFilter .
이 클래스에 의해 구현 된 모든 인터페이스는 기본 클래스 또는이 클래스 자체에 의해 선언 되는지에 관계 없이 검색 중에 고려 됩니다.
이 메서드는 기본 클래스 계층 구조를 검색 하 여 각 클래스에서 구현 하는 일치 인터페이스와 각 인터페이스에서 구현 하는 모든 일치 인터페이스를 반환 합니다. 즉, 일치 하는 인터페이스의 전이적 종료가 반환 됩니다. 중복 된 인터페이스가 반환 되지 않습니다.
현재이 Type 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우는 FindInterfaces 형식 매개 변수에 대 한 제약 조건에 선언 된 모든 인터페이스와 해당 제약 조건에 선언 된 인터페이스를 통해 상속 된 모든 인터페이스를 검색 합니다. 현재가 Type 제네릭 형식의 형식 인수를 나타내는 경우는 FindInterfaces 제약 조건과 일치 하는지 여부에 관계 없이 형식에 의해 구현 된 모든 인터페이스를 검색 합니다.
참고
FindInterfaces 제네릭 형식이 아닌 형식에 대해서도 제네릭 인터페이스를 반환할 수 있습니다. 예를 들어 제네릭이 아닌 형식은 IEnumerable<int> (Visual Basic)를 구현할 수 있습니다 IEnumerable(Of Integer) .