Get all implemented interface from a class : Reflection Assembly « Development Class « C# / C Sharp






Get all implemented interface from a class

Get all implemented interface from a class

using System;
using System.Reflection;


public class Test
{
    public static void Main(string[] args)
    {
    TheType.MyClass aClass = new TheType.MyClass();

    Type t = aClass.GetType();
    Type[] ifaces = t.GetInterfaces();
    foreach(Type i in ifaces)
      Console.WriteLine("Interface: {0}", i.Name);

    }
}



namespace TheType {
    public interface IFaceOne {
      void MethodA();
    }
    
    public interface IFaceTwo {
      void MethodB();
    }
    
    public class MyClass: IFaceOne, IFaceTwo {
      public int myIntField;
      public string myStringField;
        private double myDoubleField = 0;
        
        
        public double getMyDouble(){
          return myDoubleField;
        }
        
      public void myMethod(int p1, string p2)
      {
      }
    
      public int MyProp
      {
        get { return myIntField; }
        set { myIntField = value; }
      }
    
      public void MethodA() {}
      public void MethodB() {}
    }
}
           
       








Related examples in the same category

1.Get Method ParamemtersGet Method Paramemters
2.Get type infomation: base type, is abstract, is com object, is sealed, is classGet type infomation: base type, is abstract, is com object, is sealed, is class
3.Get all methods from a classGet all methods from a class
4.Get all fields from a classGet all fields from a class
5.Get all properties from a classGet all properties from a class
6.Using reflection to get information about an assembly
7.Demonstrate using Type class to discover information about a classDemonstrate using Type class to discover information about a class
8.Demonstrate dynamically invoking an object
9.Locate an assembly, determine types, and create an object using reflection
10.Utilize MyClass without assuming any prior knowledge
11.Uses reflection to show the inherited members of a classUses reflection to show the inherited members of a class
12.Uses reflection to execute a class method indirectlyUses reflection to execute a class method indirectly
13.Deeper Reflection: Invoking Functions
14.Illustrates runtime type invocation
15.Illustrates unloading an application domain
16.Demonstrate typeofDemonstrate typeof
17.Create an object using reflectionCreate an object using reflection
18.Uses an object in another application domain
19.Illustrates creation of an application domainIllustrates creation of an application domain