Skip to content

Instantly share code, notes, and snippets.

@seaders
Created February 4, 2015 15:08
Show Gist options
  • Save seaders/fb0e13e02fd4a342eb09 to your computer and use it in GitHub Desktop.
Save seaders/fb0e13e02fd4a342eb09 to your computer and use it in GitHub Desktop.
public class Program
{
static void Main(string[] args)
{
Pet rex;
rex = Something.MakeSomething<Pet>();
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
foreach(PropertyInfo pi in rex.GetType().GetProperties(flags) )
{
Console.WriteLine(pi.Name);
}
foreach(FieldInfo _fi in rex.GetType().GetFields(flags) )
{
Console.WriteLine(_fi.Name);
}
}
}
public class Pet
{
protected string _name;
protected int _age;
public virtual string Other { get; set; }
public virtual string Name
{
get { return _name; }
set { _name = value; }
}
public virtual int Age
{
get { return _age; }
set { _age = value; }
}
public override string ToString()
{
return string.Format("Name: {0}, Age: {1}", Name, Age);
}
public object getFieldDirect(string name)
{
return GetType().BaseType.GetField(name, BindingFlags.Instance|BindingFlags.NonPublic).GetValue(this);
}
}
/* output
Other
Name
Age
__interceptors
_name
_age
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment