GetInterfaceMap Method

Type.GetInterfaceMap Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Returns an interface mapping for the specified interface type.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Overridable Function GetInterfaceMap ( _
	interfaceType As Type _
) As InterfaceMapping

Parameters

interfaceType
Type: System.Type
The Type of the interface of which to retrieve a mapping.

Return Value

Type: System.Reflection.InterfaceMapping
An InterfaceMapping object representing the interface mapping for interfaceType.

ExceptionCondition
ArgumentException

The interfaceType parameter does not refer to an interface.

-or-

interfaceType is a generic interface, and the current type is an array type.

ArgumentNullException

interfaceType is Nothing.

InvalidOperationException

The current Type represents a generic type parameter; that is, IsGenericParameter is true.

NotSupportedException

The invoked method is not supported in the base class. Derived classes must provide an implementation.

The interface map denotes how an interface is mapped into the actual methods on a class that implements that interface.

If the current Type represents a constructed generic type, type parameters are replaced by the appropriate type arguments in the elements of the InterfaceMapping returned by this method.

The following example uses the GetInterfaceMap method to show the methods of the generic Dictionary(Of TKey, TValue) class that implement the methods of the generic IDictionary(Of TKey, TValue) interface.


Imports System.Reflection
Imports System.Collections.Generic

Class Example

    Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

        Dim obj As New Dictionary(Of Integer, String)

        If obj.GetType().GetInterface("IDictionary`2", False) IsNot Nothing Then

            ' Get the mapping between the interface methods of the 
            ' generic IDictionary interface and the Dictionary methods
            ' that implement them.
            Dim idictType As Type = GetType(IDictionary(Of Integer, String))
            Dim map As InterfaceMapping = _
                obj.GetType().GetInterfaceMap(idictType)

            Dim interfaceMethods() As MethodInfo = map.InterfaceMethods
            Dim implementationMethods() As MethodInfo = map.TargetMethods

            For i As Integer = 0 To interfaceMethods.Length - 1
                outputBlock.Text &= interfaceMethods(i).ToString() & _
                    " is implemented by:" & vbLf & "       " & _
                    implementationMethods(i).ToString() & vbLf
            Next
        End If
    End Sub 
End Class 

' This example produces the following output:
'
'System.String get_Item(Int32) is implemented by:
'       System.String get_Item(Int32)
'System.String set_Item(Int32, System.String) is implemented by:
'       Void set_Item(Int32, System.String)
'System.Collections.Generic.ICollection`1[System.Int32] get_Keys() is implemented by:
'       System.Collections.Generic.ICollection`1[System.Int32] System.Collections.Generic.IDictionary<TKey,TValue>.get_Keys()
'System.Collections.Generic.ICollection`1[System.String] get_Values() is implemented by:
'       System.Collections.Generic.ICollection`1[System.String] System.Collections.Generic.IDictionary<TKey,TValue>.get_Values()
'Boolean ContainsKey(Int32) is implemented by:
'       Boolean ContainsKey(Int32)
'Void Add(Int32, System.String) is implemented by:
'       Void Add(Int32, System.String)
'Boolean Remove(Int32) is implemented by:
'       Boolean Remove(Int32)
'Boolean TryGetValue(Int32, System.String ByRef) is implemented by:
'       Boolean TryGetValue(Int32, System.String ByRef)


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft