I have the following codes:
private PropertyInfo[] ObterPropriedades(Type classe)
{
PropertyInfo[] properties = classe.GetProperties();
return properties;
}
private string[] ObterValoresPropriedades(Type classe)
{
List<string> val = new List<string>();
foreach (var valores in ObterPropriedades(classe))
val.Add(valores.GetValue(valores,null).ToString());//aqui da o erro
return val.ToArray();
}
it is returning me the following error:
Additional information: Object does not match the target type.
How do I get the value of the properties?
And how can I pass a class as a parameter to a method?
the way I passed the class as parameter Type classe
and at the time of calling the method:
Pessoa p = new Pessoa();
ObterValoresPropriedades(p.GetType());
Is it a correct way? or are there other ways?