-3

I have to iterate through property of one object base type that i get from database and i have to check if any property i snull. Here is some code:

 req = "select * from Ga_Periodes_Absence";
 var resultat = Session.CreateSQLQuery(req).List<object>();
 foreach (var elem in resultat)
 {
     int i = 0;

     i++;
 }

resultat contains list of objects that I want to check if property of any of them is null. Any help please.

Konrad Kokosa
  • 16,563
  • 2
  • 36
  • 58
ucef
  • 557
  • 3
  • 10
  • 27
  • There a number of answers in this site addressing this question, like [How to loop through all the properties of a class?](http://stackoverflow.com/questions/531384/how-to-loop-through-all-the-properties-of-a-class). Please, do some research before posting. – rae1 Jan 21 '14 at 16:10
  • you clearly do not need an index when you use a foreach, and if by any chance you really do, you do not create it inside the loop statement – Unix von Bash Jan 21 '14 at 16:13
  • Mr Andrei, iknow why i put the index because i use it, the code is not complete. – ucef Jan 21 '14 at 16:26
  • Mr rae, i haven't time to search, and it not cause probleme to you – ucef Jan 21 '14 at 16:27

1 Answers1

1
bool result = true;    
foreach (var elem in resultat)
{
    foreach(var prop in elem.GetType().GetProperties())
    {
        if(prop.GetValue(elem) == null) result = false;
    }
}
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
  • the probleme with that is they retyrn properties of base class 'System.Object' rather than properties that i get from database – ucef Jan 21 '14 at 17:06