P
P.Sunil
I am using Reflection to print the
Fields,Methods,Constructors of a particular class.The
sample logic i am using is below.
When i am running the programme
if i am giving user input as System.Console Output is
showing correctly.But when i am giving user input as
System.Windows.Forms.Form I am getting an exception
"Object reference not set to an instance of an object."
Is ther any mistake in my programming logic.But I found
that the programme is referencing "mscorlib.dll" only.but
not other dll. Is it correct or any other problem please
rectify this.
using System;
using System.IO;
using System.Reflection;
public class reflectdemo
{
public static void Main()
{
try
{
string userinput;
System.Console.WriteLine("Enter
Full Class name");
userinput=System.Console.ReadLine
();
Type t =Type.GetType(userinput);
System.Console.WriteLine
("INFORMATION ");
System.Console.WriteLine("---------
-------------------------------------");
System.Console.WriteLine();
System.Console.WriteLine("Fields");
System.Console.WriteLine("-------
");
System.Reflection.FieldInfo[]
finfo=t.GetFields();
if(finfo.Length==0)
{
System.Console.WriteLine
("No Fields");
}
else
{
foreach(FieldInfo f in
finfo)
{
System.Console.WriteLine(f);
}
}
System.Console.ReadLine();
}
catch(System.Exception e)
{
System.Console.WriteLine
(e.Message);
System.Console.WriteLine(e.Source);
}
finally
{
System.Console.ReadLine();
}
}
}
Fields,Methods,Constructors of a particular class.The
sample logic i am using is below.
When i am running the programme
if i am giving user input as System.Console Output is
showing correctly.But when i am giving user input as
System.Windows.Forms.Form I am getting an exception
"Object reference not set to an instance of an object."
Is ther any mistake in my programming logic.But I found
that the programme is referencing "mscorlib.dll" only.but
not other dll. Is it correct or any other problem please
rectify this.
using System;
using System.IO;
using System.Reflection;
public class reflectdemo
{
public static void Main()
{
try
{
string userinput;
System.Console.WriteLine("Enter
Full Class name");
userinput=System.Console.ReadLine
();
Type t =Type.GetType(userinput);
System.Console.WriteLine
("INFORMATION ");
System.Console.WriteLine("---------
-------------------------------------");
System.Console.WriteLine();
System.Console.WriteLine("Fields");
System.Console.WriteLine("-------
");
System.Reflection.FieldInfo[]
finfo=t.GetFields();
if(finfo.Length==0)
{
System.Console.WriteLine
("No Fields");
}
else
{
foreach(FieldInfo f in
finfo)
{
System.Console.WriteLine(f);
}
}
System.Console.ReadLine();
}
catch(System.Exception e)
{
System.Console.WriteLine
(e.Message);
System.Console.WriteLine(e.Source);
}
finally
{
System.Console.ReadLine();
}
}
}