Identify the given instance

Description :


We can identify the given instance
is Class, Namespace, FullName, Abstract, Public, Interface, Enum

Following namespaces are used

using System;
using System.Reflection;




Follwoing is the code to identify the
type and details of give value

public static void ShowTypes(string name, Assembly assembly)
{
Type[] MytypeArray = assembly.GetTypes();
Console.WriteLine(name);
foreach (Type Mytype in MytypeArray)
{
if (Mytype.IsClass)
{
Console.WriteLine("\nNamespace : {0}", Mytype.Namespace);
Console.WriteLine("Class : {0}", Mytype.FullName);
if (Mytype.BaseType != null)
Console.WriteLine("Base Class : {0}",
Mytype.BaseType.FullName);
else
Console.WriteLine("Class not derived from anything");

if (Mytype.IsAbstract)
Console.WriteLine("Abstract base class");
else
Console.WriteLine("Instantiable class");
if (Mytype.IsPublic)
Console.WriteLine("Scope: Public");
else
Console.WriteLine("Scope: Private");
}
else if (Mytype.IsInterface)
{
Console.WriteLine("\nNamespace : {0}", Mytype.Namespace);
Console.WriteLine("Interface : {0}", Mytype.FullName);
if (Mytype.IsPublic)
Console.WriteLine("Scope: Public");
else
Console.WriteLine("Scope: Private");
}
else
if (Mytype.IsEnum)
{
Console.WriteLine("\nEnumeration: {0}", Mytype.FullName);
}
else
Console.WriteLine("\nType: {0}", Mytype.FullName);
}
}
public static void Main(string[] args)
{
for (int i = 0; i < args.Length; ++i)
{
Assembly Myassembly = Assembly.LoadFrom(args[0]);
ShowTypes(args[0], Myassembly);
}
}



By
Nathan


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: