@meziantou@hachyderm.io avatar

meziantou

@meziantou@hachyderm.io

Microsoft MVP, Software engineer, blogger

This profile is from a federated server and may be incomplete. Browse more on the original instance.

meziantou, to dotnet
@meziantou@hachyderm.io avatar
meziantou, to dotnet
@meziantou@hachyderm.io avatar
meziantou,
@meziantou@hachyderm.io avatar

@khalidabuhakmeh As mentioned in the post, a class can be a better solution as you can take advantage of the compiler to be type-safe. Also, the IDE are not very good when showing the type as they do not preserve the alias, so I think aliases may be good for private local usages.

meziantou, to dotnet
@meziantou@hachyderm.io avatar
meziantou, to dotnet
@meziantou@hachyderm.io avatar
meziantou, to dotnet
@meziantou@hachyderm.io avatar
jchannon, to dotnet
@jchannon@hachyderm.io avatar

there has to be an easier way to install browsers for use in tests in CI via #dotnet playwright

meziantou,
@meziantou@hachyderm.io avatar

@jchannon You can install browsers from your code:
Microsoft.Playwright.Program.Main(new[] { "install" });

https://www.meziantou.net/distributing-applications-that-depend-on-microsoft-playwright.htm

bradwilson, to dotnet
@bradwilson@mastodon.social avatar

There is an unfortunate side-effect of writing #Roslyn #Analyzers with respect to compatibility.

The @xunit analyzers target Microsoft.CodeAnalysis 4.2.0 because that's what in VS 2022 17.2, which is currently still in LTS support.

CodeAnalysis 4.2.0 doesn't support C# 12. There are analyzers that are broken because of this, when used with C# 12 language features, and we can't fix them unless we're willing to throw away compatibility with everything before VS 2022 17.8.

#dotnet #csharp

meziantou,
@meziantou@hachyderm.io avatar

@bradwilson @jasonmalinowski I don't know if there is a documentation. You can read the following GitHub issue https://github.com/dotnet/sdk/issues/20355.
The solution is to create one folder per Roslyn version in the NuGet package. The best version will be selected based on the current version of Roslyn. Here's an example from Meziantou.Analyzer

bradwilson, to dotnet
@bradwilson@mastodon.social avatar

I want CA2007 to be smarter.

There's no need to keep re-calling .ConfigureAwait(false) on every single task. The first one is good enough. I've already been shifted off the SyncContext, if there was one.

meziantou,
@meziantou@hachyderm.io avatar

@bradwilson That's not true if the task is synchronous. For example:
await Task.CompletedTask.ConfigureAwait(false);
// Still on the same context

bradwilson, to random
@bradwilson@mastodon.social avatar

#Roslyn gripe:

Why doesn't editor.ReplaceNode() take a collection of nodes to use as a replacement? Instead I have to write:

editor.InsertAfter(oldNode, newNodes);
editor.RemoveNode(oldNode);

And then as a bonus, it destroys some of the trivia along the way (like deleting a blank line that it shouldn't delete). (That part may be my fault, I haven't figured out whether I've actually fixed my other bug yet.)

meziantou,
@meziantou@hachyderm.io avatar

@bradwilson @KirillOsenkov In the case of Meziantou.Analyzer, some issues could only repro with specific versions of Roslyn. That's why the CI run the tests against many versions. Also, you can add #error version to your code to get the current version of Roslyn.

meziantou, to dotnet
@meziantou@hachyderm.io avatar
meziantou, to dotnet
@meziantou@hachyderm.io avatar
jasonbock, to random
@jasonbock@mstdn.social avatar

TIL (meaning, Tonight I Learned) that you can declare non-optional parameters after optional ones in C#.

Just create an indexer with optional parameters:

int this[int a, string b = "b"] { get; set; }

The IL for the set method is this:

instance void set_Item (
int32 a,
[opt] string b,
int32 'value'
) cil managed
{
.param [2] = "b"
}

Note that the "value" is after b.

meziantou,
@meziantou@hachyderm.io avatar

@jasonbock Or you can use the attributes instead of the C# syntax

khalidabuhakmeh, to dotnet
@khalidabuhakmeh@mastodon.social avatar

Did you know that you should use TextElementEnumerator to determine the length of a string if the input might have Unicode emojis? Check out the sample below.

I'm curious if future versions of should do this check implicitly. 🤔

meziantou,
@meziantou@hachyderm.io avatar
meziantou, to dotnet
@meziantou@hachyderm.io avatar
meziantou, to dotnet
@meziantou@hachyderm.io avatar
meziantou,
@meziantou@hachyderm.io avatar

@khalidabuhakmeh Can you provide a link to the documentation showing how to configure it?

meziantou,
@meziantou@hachyderm.io avatar

@khalidabuhakmeh Rider rules is different from my analyzer! Meziantou.Analyzer's rule validates that values for a specific log parameter always have the configured type. So, it must be configured.

khalidabuhakmeh, to dotnet
@khalidabuhakmeh@mastodon.social avatar

2023.2 EAP 8 brings with it Assembly Diffing! If you’re wondering if the “latest” got released to production, well… guess no more!

https://blog.jetbrains.com/dotnet/2023/07/10/resharper-2023-2-eap-8/

meziantou,
@meziantou@hachyderm.io avatar

@khalidabuhakmeh It's nice to see new great features, but would it be possible to fix the razor parser? https://youtrack.jetbrains.com/issue/RSRP-486480/Razor-Support-RenderFragment-syntax. The issue was reported 2.5 years ago, and Rider still reports errors for valid files... Is Razor part of the roadmap?

meziantou, to dotnet
@meziantou@hachyderm.io avatar
  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • thenastyranch
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • ngwrru68w68
  • provamag3
  • magazineikmin
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • JUstTest
  • All magazines