Подавление устаревших предупреждений в VB.NET

Чтобы расширить ответ @mechnicov: внутри цикла используйте имя локальной переменной objective, а не имя переменной экземпляра @objective. NoMethodError точно говорит вам, в чем проблема. Объект, для которого вы вызвали метод, равен nil, поскольку он не был определен.

Вот простой пример актуальной проблемы:

[:a, :b, :c].each { |item| print @item.capitalize }
# NoMethodError: undefined method `capitalize' for nil:NilClass
# the instance variable @item is an instance of NilCLass

[:a, :b, :c].each { |item| print item.capitalize }
# ABC=> [:a, :b, :c] 

В rails вы определяете переменные экземпляра объекта модели внутри контроллера. Перебирая их в представлении, вы используете локальную переменную, назначенную в вашем цикле.

14
задан Peter Mortensen 26 October 2015 в 13:40
поделиться

2 ответа

If you're using Visual Studio you can do the following.

  1. Right click on the project and select "unload"
  2. Right click on the project and select "Edit SomeProjectName.vbproj"
  3. You should see two XML element tags with the name "NoWarn". Add the number 40000 to the list of numbers already present (make sure to do this for every NoWarn tag in the file)
  4. Save the file
  5. Right click on the project and select reload (you'll have to close the .vbproj file)

This will get rid of the warning. The number 40000 is the VB.Net error number for the obselete warning. You can suppress any warning in this fashion.

Note: If the NoWarn tag is not present, add it to the main PropertyGroup element with the following values

<NoWarn>40000</NoWarn>
18
ответ дан 1 December 2019 в 12:39
поделиться

In VS.NET you can right click on and suppress code analysis warnings. This will add the attribute for you.

However, the "don't use obsolete APIs" warning is not coming from code analysis, and so the SurpressMessage attibute won't work. This is a compiler warning.

For VS.NET you'd need to switch off this warning with...

/nowarn:0618

... at the command line (or just adding "0618" into the Suppress Warnings field on the csproj properties). You should do the same with whatever the VB warning number is.

4
ответ дан 1 December 2019 в 12:39
поделиться
Другие вопросы по тегам:

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