You should be able to get the FieldInfo
for the variables within the type using the GetField(...)
or GetFields(...)
method on the main type. Below is a short program demonstrating how you might go about it:
class Program
{
public string mStringType = null;
static void Main(string[] args)
{
var program = new Program();
try
{
var field = program.GetType().GetField("mStringType");
Console.WriteLine("Field '{0}' is of type '{1}' and has value '{2}'.", field.Name, field.FieldType.FullName, field.GetValue(program));
program.mStringType = "Some Value";
Console.WriteLine("Field '{0}' is of type '{1}' and has value '{2}'.", field.Name, field.FieldType.FullName, field.GetValue(program));
}
catch (NullReferenceException)
{
Console.WriteLine("Error");
}
Console.ReadKey();
}
}
This gives the following output on the Console window:
Field 'mStringType' is of type 'System.String' and has value ''.
Field 'mStringType' is of type 'System.String' and has value 'Some Value'.
Note: If the fields are not public
, you will have to pass some BindingFlags
into the GetField(...)
or GetFields(...)
methods.