Visual Studio: Сделайте отладчик знающим, что функция не вызывает “побочные эффекты”

Для atyourservice.com.cy мы используем серверные отрендеренные шаблоны для страниц, особенно для покрытия самой части. И использование API для взаимодействия после загрузки страницы. Поскольку наша структура MVC, все функции контроллера дублируются на вывод json и вывод html. Шаблоны чистые и получают только объект. Это может быть преобразовано в JS шаблоны в считанные секунды. Мы всегда поддерживаем шаблоны на стороне сервера и просто возвращаемся к js по запросу.

16
задан 26 June 2009 в 17:36
поделиться

2 ответа

No this is not possible. The determination of whether or not a function will have side effects is actually made by the language specific expression evaluator.

Both C# and VB.Net have different EE's and each has it's own determination of whether on not a function causes side effects. In general though, they both consider an explicit function call to have side effects and will not process them in situations, such as stepping, where the debugger wants to disable side effects.

The easiest way to work around this though is to use a Property. By default Property instances are not considered to have side effects and they will evaluate on step.

EDIT

Wanted to clear up some misconceptions. Neither the debugger or expression evaluator will do any sort of method inspection to determine if a function has side effects. They simply note the presence of a function and label it as potentially having side effects. They don't attempt to inspect the code of the method in any way.

3
ответ дан 30 November 2019 в 22:02
поделиться

Вы пытались сделать это таким что функция не изменяет свойства класса или глобальные переменные? Мое неофициальное определение «побочных эффектов» - это «изменения в среде выполнения, которые вносятся во время выполнения функции». Итак, эта функция вызывает побочные эффекты:

void addValues(int operand1, int operand2) {
  globalSum = operand1 + operand2;
}

, но не эта функция:

int addValues(int operand1, int operand2) {
  return operand1 + operand2;
}

Всегда лучше избегать побочных эффектов, когда это возможно. Они могут вызвать проблемы при отладке. См. эту статью в Википедии .

-2
ответ дан 30 November 2019 в 22:02
поделиться
Другие вопросы по тегам:

Похожие вопросы: