Can you get the current project from an Analyzer? - roslyn-code-analysis

I’d like to write a Analyzer that adds either Option Strict Off or Option Strict On, which seems like it would be easy to do ... if the Analyzer can get access to a files project.

The context has a property Compilation, which has the property CommonOptions a VisualBasicCompilationOptions, which has the Property OptionStrict which allows me to determine if the project has strict on as a default or not.

Related

Globally Tag EF Core Queries with ".TagWithCallSite()"

With the release of the .TagWithCallSite() method in EF Core 6.0 I was wondering if there is a way to apply this globally on every query run via a DbContext in some way?
It would be much better to apply this across the whole project without having to put it on each query individually.
TagWithCallSite accepts parameters marked with CallerFilePathAttribute and CallerLineNumberAttribute which are filled in by compiler (or manually if needed) during build so it is impossible to set up globally.
No, you cant't do that.
When you explicitly define TagWithCallSite(), complier automatically fills default parameters filePath and lineNumber. It is not possible to define that for all queries because compiler do not store such information in Expression Tree.

Assign build clean option at queue time

i have a bitbucket classic build pipeline and i need to have the ability to set the build clean option at queue time. it seems like this used to be possible via the Build.Clean variable but that has since been deprecated.
When editing a build pipeline the Clean option uses an editable drop down but anytime you try and type something, it erases what you just wrote. i would like to set this option to a variable like $(CleanBuild)
Assign build clean option at queue time
Indeed, the variable Build.Clean is already deprecated. But the document Use predefined variables provided another variable Build.Repository.Clean, which will help us to clean the Sources:
Besides, if you want to clean other options fields, like All build directories:
I do not believe there is a way to assign the clean options at queue-time. Even if we use deprecated Build.Clean variable, we still can clear Sources only.
You could check the similar thread for some more details.
Hope this helps.

STM32Cube: FreeRTOS 10.0.1 and CMSIS v2 generate warnings

I'm using STM32Cube to generate an IAR EW 8.2 project with FreeRTOS 10.0.1 and CMSISv2 API's. When I clean up the project and build again, I get the following warnings
Warning[Pe177]: variable "hTask" was declared but never referenced
Warning[Pe177]: variable "hTimer" was declared but never referenced
Warning[Pe177]: variable "hEventGroup" was declared but never referenced
Warning[Pe177]: variable "hSemaphore" was declared but never referenced
Warning[Pe177]: variable "hQueue" was declared but never referenced
I know that these warnings should not affect my code but I would be interested if this warnings are always there or if they depend on my settings.
These are warnings being generated by IAR's compiler. They'll go away after those variables are used. If they aren't used. . . get rid of them and the warnings will also go away ;-) Dead code is never a good thing to keep around! Specifically, you should really consider treating warnings more like errors, since it will force a cleaner code base.
If you really want to supress warnings, you can mask individual warnings in IAR:
1. Select Project-->Options-->Compiler tab
2. Select Suppress these diagnostics and specify your desired warning
3. Click OK.

PhpStorm 8.0 - How enable code completion in another file?

I implement MyClass containing the method method() and I store the instance in $_ENV['key'] in test.php. Also in test.php the code completion works when I type $_ENV['key']->.
In test2.php I include test.php and the code completion does not work any more for $_ENV['key']->.
Does anyone know how to enable this in PhpStorm?
AFAIK type tracking for arrays works within the same file only.
You can bypass it via intermediate variable (yes, it's not a nicest solution) and small PHPDoc comment, like this:
/** #var MyClass $myVar */
$myVar = $_ENV['key'];
$myVar->
P.S.
In general, I'd suggest not using global arrays this way (or even not using global vars at all -- only very basic stuff during bootstrap, if possible). Instead (based on your code) I may suggest using some static class (as one of the alternatives) with dedicated field where you can easily give type hint (via PHPDoc) to a class field -- this way IDE will always know hat type it is. Current PHP versions (5.5 and especially 5.6) work with objects nearly as fast as with arrays, even leading in (smaller) memory consumption.
Obviously, such suggestion does not really apply if this code is not yours.

MEF: Importing on Fields

Is it recommended that we place an Import on a property instead of a field? I tried it on a field and it is working but Resharper is telling me a warning that the field was never initialized.
ReSharper doesn't recognize that MEF will be setting the variable and since there is no guarntee that MEF will be setting the variable (example if it isn't put into a container for example), so it is reasonable for ReSharper to warn about this. You can either ignore it or simply initialize the field to null (or default(T)).
As for whether or not you should use a property or field I think using a field is fine (assuming it is not public). I generally reserve properties for things I want to expose publicly. One special case to consider here is that there are some issues having Imports on private members in low trust scenarios like SL or paritial trust because MEF uses reflection and you cannot use private reflection in some of those scenarios.