using System;
using System.Reflection;
namespace Reflect
{
class Profile
{
private string name;
private string phone;
public Profile()
{
name = ""; phone = "";
}
public Profile(string name, string phone)
{
this.name = name;
this.phone = phone;
}
public void Print()
{
Console.WriteLine("{0}, {1}", name, phone);
}
public string Name { get; set; }
public string Phone { get; set; }
}
class MainApp
{
static void Main(string[] args)
{
Type type = Type.GetType("DynamicInstance.Profile");
MethodInfo methodinfo = type.GetMethod("Print");
PropertyInfo NameProperty = type.GetProperty("Name");
PropertyInfo PhoneProperty = type.GetProperty("Phone");
object profile = Activator.CreateInstance(type, "박상현", "512-1234");
methodinfo.Invoke(profile, null);
profile = Activator.CreateInstance(type);
NameProperty.SetValue(profile, "박찬호", null);
PhoneProperty.SetValue(profile, "997-5511", null);
Console.WriteLine("{0} {1}", NameProperty.GetValue(profile, null), NameProperty.GetValue(profile, null));
}
}
}
예외 발생되는데 왜뜨는지 모르겟서유 ㅠㅠ
Type type = Type.GetType("DynamicInstance.Profile"); ->Type type = Type.GetType(" Reflect.Profile");
ㄴ우와 무슨 차이인거죠?? DynamicInstance 가 뭔지 몰라서 계속찾아봣는데 안나오더라구요 ㅠㅠ
ㄴ 네임스페이스 공부하셈.
ㄴ 아 해당 네임스페이스를 참조해서 불러오는건가용??