lsoft / SyncToAsyncExtension

A Visual Studio extension (VSIX) which creates codelenses allowed to go to sync sibling method for async methods and vice-versa.
MIT License
1 stars 0 forks source link

Convert class CodeLensSibling to a positional record #3

Closed virzak closed 8 months ago

virzak commented 8 months ago

https://github.com/lsoft/SyncToAsyncExtension/blob/1a071280952cb4985222f3bf2c3da1df2cccf9ab/Shared/Dto/CodeLensSibling.cs#L5-L11

This construction looks like a perfect candidate for a record:

public record CodeLensSibling(
  Guid ProjectGuid,
  Guid DocumentGuid,
  string FilePath,
  bool IsSourceGeneratedDocument,
  string MethodName,
  string MethodBody,
  int? MethodSpanStart,
  int? MethodSpanLength);
lsoft commented 8 months ago

@virzak VSIX has the target net48 and appropriate langversion:

    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <LangVersion>8.0</LangVersion>

(because VS itself is net 4.8 application).

LangVersion 8.0 is not supporting records... there are compilation errors.

Bumping LangVersion above is not safe, as I can read.

Choosing a language version newer than the default can cause hard to diagnose compile-time and runtime errors.

To be honest, we have net48 application at my work too, but with lang=latest and did not see any error for few years. But VSIX development is different by its nature, we are injecting into the app, VS...

so I would prefer not to play with fire.

Thanks for you suggestion!

virzak commented 8 months ago

Fair enough. And obviously this was just a suggestion, which has no effect of any of what I do, but could potentially reduce the your amount of work in the future.

One last thing about it is that Mads Kristensen almost never uses preview either. Except here:

https://github.com/madskristensen/ImagePreview/blob/68696148057fa2c1a3559d1203b181c06affa984/src/ImagePreview.csproj#L5C18-L5C25

@madskristensen, could weigh in?

madskristensen commented 8 months ago

I don't have much to say here. I like to use latest which seems to work most of the time even on GitHub Actions CI workflows.