Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
        empsupp.isGoodCitizenCalculated ;
        empsupp.iscomplyWithAllRegReqCalculated;

        empsupp.isIndustrySpendCalculated;
        empsupp.isJobCreationCalculated ;
        empsupp.isMaterialTransCalculated ;
        empsupp.isSkillTransCalculated;
        empsupp.isServiceIndLabCostCalculated;

empsupp is object of a class and the properties listed above are type of bool.

Now I have to return an overall status on basis of this calculation:-------------

if any 3 of the last 5 (note: not all property,just take last 5 ) property value found true,then over all status will be true,otherwise false.

I would have done it by simple if else,but I think that is not proper way because if I have to check 100 properties,then?
Posted

1 solution

Please check

C#
public int CountBooleanValue(object data)
    {
        int count = 0;
        foreach (PropertyInfo propertyInfo in data.GetType().GetProperties().Skip(5))
        {
            if (propertyInfo.PropertyType == typeof(bool))
            {
                bool value = Convert.ToBoolean(propertyInfo.GetValue(data, null));
                if (value == true)
                {
                    count++;
                }

            }
        }

        return count;
    }
 
Share this answer
 
v2
Comments
souvikcode 1-Dec-15 3:35am    
Thanks.it works."skip" create the magic.
souvikcode 1-Dec-15 3:36am    
But i have to set the properties (ehich will be checked) at the last,right?because we can tell loop to check from 5th to 10th.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900