Suppose I have the following code:
public class SomeClass()
{
private readonly object _lock = new object();
public void SomeMethodA()
{
lock
There's a fundamental problem with your request. Suppose there were a IsLockHeld() method and you'd use it like this:
if (not IsLockHeld(someLockObj)) then DoSomething()
This cannot work by design. Your thread could be pre-empted between the if() statement and the method call. Allowing another thread to run and lock the object. Now DoSomething() will run, even though the lock is held.
The only way to avoid this is to try to take the lock and see if it worked. Monitor.TryEnter().
You see the exact same pattern at work in Windows. There is no way to check if a file is locked by another process, other than trying to open the file. For the exact same reason.