using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ReflectionTe
{
public class Blog
{
private static int PostsCount
{
get
{
return 10000;
}
}
private string GetDescription()
{
return @"A weblog dedicated to obsessively profiling
reviewing new Internet products and companies";
}
private string ChangeBlogName(string newName)
{
name = newName;
return name;
}
string url = "http://techcrunch.com";
string name = "Tech Crunch";
}
class Program
{
static void Main(string[] args)
{
Blog blog = new Blog();
Type type = typeof(Blog);
BindingFlags privateBindings = BindingFlags.NonPublic | BindingFlags.Instance;
FieldInfo[] fieldInfos = type.GetFields(privateBindings);
foreach (FieldInfo fieldInfo in fieldInfos)
{
Console.WriteLine(fieldInfo.Name + " " + fieldInfo.GetValue(blog));
}
PropertyInfo[] propertyInfos = type.GetProperties(privateBindings | BindingFlags.Static);
foreach (PropertyInfo propertyInfo in propertyInfos)
{
Console.WriteLine(propertyInfo.Name + " " + propertyInfo.GetValue(null, null));
}
MethodInfo miGetDescription = type.GetMethod("GetDescription", privateBindings);
object retObj = miGetDescription.Invoke(blog, new object[] { });
Console.WriteLine(retObj);
MethodInfo miChangeBlogName = type.GetMethod("ChangeBlogName", privateBindings);
retObj = miChangeBlogName.Invoke(blog, new object[] { "Yahoo blog" });
Console.WriteLine(retObj);
Console.ReadLine();
}
}
}