C
C#17mo ago
Alexicon

❔ Suppress Visual Studio IDE0270 style rule without adding '.editorconfig'

I have some cases in my code where I have if statements like the following:
User? user = Users.FirstOrDefault(u => u.Id == id);

if (user is null)
{
throw new UserDoesNotExistException();
}
User? user = Users.FirstOrDefault(u => u.Id == id);

if (user is null)
{
throw new UserDoesNotExistException();
}
But the visual studio 'Error List' shows 'messages' that say 'Null check can be simplified' (fg. 1) which in some cases I am ok with simplifying but with the above example it would want to make it like this:
User user = Users.FirstOrDefault(u => u.Id == id) ?? throw new UserDoesNotExistException();
User user = Users.FirstOrDefault(u => u.Id == id) ?? throw new UserDoesNotExistException();
Which I personally don't like in this case. So how can I suppress this specific rule style code? I know you can configure code style within the code style section of the settings (fg. 2) but I have the 'perfer throw-expression' already set to 'no' so I don't know why this message still shows up. Obviously you can add a .editorconfig to the actual project but I do not want to do that. I want it as part of the permanent code style within my visual studio. Maybe this is just bugged? If you click the link in the error list for this error code 'IDE0270' it takes you to a 404... (https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0270).
fg. 1
fg. 2
5 Replies
whiteviperx
whiteviperx17mo ago
// Disable IDE0270 I think that should work
Alexicon
Alexicon17mo ago
@whiteviperx Maybe but like I said I want to make it permanent since I am working in several solutions and I don't want to modify the repositories. All other code styles I have managed to configure but this one.
whiteviperx
whiteviperx17mo ago
An odd idea might be to add it the the default header?? if you get a chance can you look at my question? You could also try this ... create the editorconfig file and put it in the folder C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE.... or similar??? just a thought
Alexicon
Alexicon17mo ago
@whiteviperx that might work. I am away right now but will try that when I get a chance
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ xaml questionIs it possible to use custom parameters for a template in xaml? So for example if i want to use a gr❔ How to Require Property for Serialization?Hello, I'm working on a library for the Unity game engine that interfaces with an API. Some of the ❔ Is there a way to get Textchunk Width?something like TextChunk.GetWidth() which to get a character width..not the TextChunk.CharSpaceWidth❔ protocol for sending small amounts of data for long periods of timeWhat the title says:) I was thinking between mqtt or grpc, maybe just websockets? But the pub/sub mo❔ Efficient way to query this problemI have a logic question. Right now, I'm doing it the worst way possible... Which is s adly the only ❔ Can't build wpf project. "TestClassifier_w04izrw3_wpftmp.csproj" -- FAILED.I'm trying to build a WPF project and I keep seeing the build error: `Done building project "TestCla❔ repo doesnt connect to github on another pcmy repo (solution) is on a usb stick, i've created it on another pc and pushed it to github, now i a❔ How to get hostname string ?i need the hostname string in MappingProfile for automapper i have no access to `HttpContext.CurrenHow to get and set position of an ui element via code wpf c#Hello i want to create TextBoxes via code and set their position but i can't found how to even get tLooking for somebody who can teach me using C# language, simple things for 2D games, going to pay💰I’m looking for somebody who can teach me the C# language so I can begin creating a 2D game, I will