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.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- interfaceType
- Type: System.Type
The Type of the interface of which to retrieve a mapping.
Return Value
Type: System.Reflection.InterfaceMappingAn InterfaceMapping object representing the interface mapping for interfaceType.
| Exception | Condition |
|---|---|
| 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 null. |
| 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<TKey, TValue> class that implement the methods of the generic IDictionary<TKey, TValue> interface.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
using System; using System.Reflection; using System.Collections.Generic; class Example { public static void Demo(System.Windows.Controls.TextBlock outputBlock) { Dictionary<int, string> obj = new Dictionary<int, string>(); // Get the mapping between the interface methods of the // generic IDictionary interface and the Dictionary methods // that implement them. if (obj.GetType().GetInterface("IDictionary`2", false) != null) { Type idictType = typeof(IDictionary<int, string>); InterfaceMapping map = obj.GetType().GetInterfaceMap(idictType); MethodInfo[] interfaceMethods = map.InterfaceMethods; MethodInfo[] implementationMethods = map.TargetMethods; for(int i=0; i<interfaceMethods.Length; i++) { outputBlock.Text += interfaceMethods[i].ToString() + " is implemented by:\n " + implementationMethods[i].ToString() + "\n"; } } } } /* 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) */
Note: