3
Good morning, everyone. I have a problem that I believe can be solved with Reflection, but I do not know how to use and I hope you can help me in my difficulty.
I have an object that will be passed as a parameter to a specific method. This method should be able to read this generic object and identify the name of all fields of this object. Below the example.
public class Aluno
{
public int Id {get;set;}
public string Nome {get;set;}
}
The method below will receive this object and needs to go through it and identify the name of the fields, that is, it needs to discover that a field is called Id and the other is called Name. Example below:
public void DescobridorDeNome(T Objeto)
{
//Aqui ele vai descobrir o nome dos campos do objeto.
}
So this method that I believe using Reflection will solve. Does anyone know how I can do it?
Thanks.
As for the doubling of the question, I’m sorry, but I didn’t know how to look for the question, so I posted explaining exactly how I would need it. It was really bad.
– Thiago Henrique