Check if a type is a abstract class or interface or just a base class
I need a method that takes class name as a parameter and returns me if the type is an abstract class or interface or a base class or in generic the type of the data type that I pass as a parameter.

Sukesh MarlaPosted Aug 12, 2012, 11:13 PM
No for base class thing, There is no easy method
you have to loop.
Hope It Helped. Please Check This is Currect Answer.
Akkiraju IvaturiPosted Aug 12, 2012, 8:40 PM
VulpesPosted Aug 12, 2012, 8:35 PM
Akkiraju IvaturiPosted Aug 12, 2012, 3:57 PM
Thanks for sending the code for checking it a type is interface or a abstract class or a base class.
I know there is a direct method where you can find it it is an interface or abstract class. But, in your code all the classes are shown as base classes in the output where as Class B is only the base class since ClassA is abstract first and so the code cannot check if it is a base class.
Anyways I would like to mark only the base classes as base class otherwise just class.
Sukesh,
Thanks to you to send me the code to check the same.
Guys,
I believe we need to loop through all the classes to identify for each class if there are sub classes and then if it has, then it is a base class as below:
Here for each class, you need to pass the class to the getclasses to check if it has child classes. I would like to hear from you if you have any easy method to accomplish the same
Sukesh MarlaPosted Aug 12, 2012, 11:10 AM
{
}
.
.
.
.
class Program
{
public static void FindInformation(Type t)
{
if(t.IsInterface)
{
Console.WriteLine("I am interface");
}
else if(t.IsAbstract)
{
Console.WriteLine("I am Abstract");
}
if(t.IsGenericType)
{
Console.WriteLine("I am Generic \nAnd Generic paramters are");
foreach(Type generc in t.GetGenericArguments())
{
Console.WriteLine(generc.Name);
}
}
}
public static void Main()
{
Type t = typeof(MyClass
FindInformation(t);
Console.ReadKey();
}
}
Hope It Helped. Please Check This is Currect Answer.
VulpesPosted Aug 12, 2012, 11:07 AM
The output should be: