Reflecting Something
Reflection ile bir dll in içindeki method ve property’lere erişmeyi gösteren küçük bir örnek…
Önce Activator.CreateInstance ile nesnenin örneğini oluşturuyoruz, sonra GetProperty ile özelliği alıp SetValue ile de değeri veriyoruz…
GetMethod().Invoke() ile de class’ın içinden bir metodu çalıştırabiliriz…
BaseReport rpt = Activator.CreateInstance(Type.GetType("ReportClass")) as BaseReport; rpt.GetType().GetProperty("Paremetre").SetValue(rpt, "Ankara", null); rpt.GetType().GetMethod("Work").Invoke(rpt, new object[] { "Parametre" });
Category: Csharp - C# - Comment »




