3

I need a way to dynamically populate this query... to avoid repeating the same query which I will have to do about 20 times

public decimal percentage_of_property(string property)
{
    var total = Routines().Where(r=>r.property==true).Count();
    return (decimal)100 * total / routines_total();
}

This obviously doesn't work... but I put it there so you can see what I'm trying to achieve...

Thanks in advance.

1 Answer 1

2

Assuming Routine is the type you can avoid reflection and use functional programming like so:-

public decimal percentage_of_property(Func<Routine, bool> propertyTest)
{
    var total = Routines().Where(r => propertyTest(r)).Count();
    return (decimal)100 * total / routines_total();
}

use it like:-

percentage_of_property(r => r.propertyName)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.