You can build expressions dynamically but not as simply as your pseudo code - it requires reflection and expression trees (read this).

A simple way to accomplish what it seems like you'd like to do is to short circuit different parts of the predicate using boolean flags:

bool testMachineName;
bool testIsServer;

r = r.Where( x =>
    ( !testMachineName || iEnumerableMachineNames.Contains( x.Machine.Name ) ) ||
    ( !testIsServer || x.Server ) );

Related Articles