.NET : Detecting standard input redirection

How to detect if some data has been piped to the standard input of a C# .NET console program? The issue is that reading or peeking the standard input stream is a blocking operation with a regular console stream. There seems to be no obvious way to do that. But there is a dirty workaround.

static bool stdin_isatty()
// True : stdin is not redirected. False : stdin is redirected and readable at once.
{
    bool result = true;
    try
        {
            if (Console.KeyAvailable) {}
        }
    catch (InvalidOperationException e)
        {
            result = false;
        }
    return result;
}