Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing lambdas from being stepped into when hosting method is DebuggerHidden

Tags:

c#

private static void Main()
{
    Console.WriteLine(GetRandomInteger());
    Console.ReadLine();
}

[DebuggerHidden]
private static int GetRandomInteger()
{
    Func<int> random = () => 4;
    return GetRandomInteger(random);
}

[DebuggerHidden]
private static int GetRandomInteger(Func<int> random)
{
    return random();
}

Using the code above, is there a way to prevent the Func<int> random = () => 4; line from getting stepped into when debugging?

like image 660
Austin Salonen Avatar asked May 20 '13 18:05

Austin Salonen


2 Answers

Well you could use a private function with the [DebuggerHidden] attribute instead of a labmda, and set the Func<int> delegate to the private function.

like image 173
Christopher Stevenson Avatar answered Nov 10 '22 21:11

Christopher Stevenson


[DebuggerHidden] can be used on a property, and this property appears to behave as you would like:

[DebuggerHidden]
private static Func<int> random
{
  get { return () => 4; }
}

It is a workaround, like the other answer; however, it keeps the lambda and may be closer to the original intent.

like image 34
Joel Rondeau Avatar answered Nov 10 '22 22:11

Joel Rondeau