Npr:
Code:
public class Osoba
{
public string Ime { get; set; }
public string Prezime { get; set; }
}
public class NekaKlasa
{
private static void NekaMetoda(Osoba obj, string propertyName)
{
if (obj.GetType().GetProperty(propertyName).GetValue(obj, null) != null)
{
//do something
//...
}
}
}
public class Osoba
{
public string Ime { get; set; }
public string Prezime { get; set; }
}
public class NekaKlasa
{
private static void NekaMetoda(Osoba obj, string propertyName)
{
if (obj.GetType().GetProperty(propertyName).GetValue(obj, null) != null)
{
//do something
//...
}
}
}
I sad ako pozovem NekaKlasa.NekaMetoda(obj, "Ime") to bi trebalo da prođe, a ako pozovem NekaKlasa.NekaMetoda(obj, "NepostojeciProperty") da dobijem compile time error.