Get all matching Interface Types as compared to an unknown object x.
[C#]
/// <summary> /// Get all matching Interface Types as compared to an unknown object x. /// </summary> /// <param name="anAssembly">A System.Reflection.Assembly that is a .NET Assembly. This would be created by System.Reflection.Assembly.LoadFrom() Method. Example: the Assembly ESRI.ArcGIS.Carto</param> /// <param name="x">A System.Object that is a Class to interrogate. Example: ESRI.ArcGIS.Carto.EnvelopeClass</param> /// <returns>A System.Collection.ArrayList containing a series of System.String values.</returns> /// <remarks></remarks> public System.Collections.ArrayList GetInterfaces(System.Reflection.Assembly anAssembly, object x) { // Create an ArrayList to store the names (strings) of Interfaces that are used by an unknown object x System.Collections.ArrayList returnArrayList = new System.Collections.ArrayList(); //Get the Type of the unknown object x System.Type xType = x.GetType(); //For a specified .NET Assembly obtain all of it's Types in an Array System.Type[] assemblyTypes = anAssembly.GetTypes(); //Loop through all of the Types in the .NET Assembly foreach (System.Type assemblyType in assemblyTypes) { //If the Assembly Type is an Interface proceed if (assemblyType.IsInterface) { //If the Assembly Type matches the unknown object x Type proceed if (assemblyType.IsInstanceOfType(x)) { //Add the fully qualified Interface name of the Assembly Type to the ArrayList returnArrayList.Add(assemblyType.FullName); } } } //Return the ArrayList of matched Initerface names return returnArrayList; }
[Visual Basic .NET]
''' <summary> ''' Get all matching Interface Types as compared to an unknown object x. ''' </summary> ''' <param name="anAssembly">A System.Reflection.Assembly that is a .NET Assembly. This would be created by System.Reflection.Assembly.LoadFrom() Method. Example: the Assembly ESRI.ArcGIS.Carto</param> ''' <param name="x">A System.Object that is a Class to interrogate. Example: ESRI.ArcGIS.Carto.EnvelopeClass</param> ''' <returns>A System.Collection.ArrayList containing a series of System.String values.</returns> ''' <remarks></remarks> Public Function GetInterfaces(ByVal anAssembly As System.Reflection.Assembly, ByVal x As System.Object) As System.Collections.ArrayList ' Create an ArrayList to store the names (strings) of Interfaces that are used by an unknown object x Dim returnArrayList As New System.Collections.ArrayList 'Get the Type of the unknown object x Dim xType As System.Type = x.GetType 'For a specified .NET Assembly obtain all of it's Types in an Array Dim assemblyTypes As System.Type() = anAssembly.GetTypes 'Loop through all of the Types in the .NET Assembly Dim assemblyType As System.Type For Each assemblyType In assemblyTypes 'If the Assembly Type is an Interface proceed If assemblyType.IsInterface Then 'If the Assembly Type matches the unknown object x Type proceed If assemblyType.IsInstanceOfType(x) Then 'Add the fully qualified Interface name of the Assembly Type to the ArrayList returnArrayList.Add(assemblyType.FullName) End If End If Next 'Return the ArrayList of matched Initerface names Return returnArrayList End Function