bradwilson,
@bradwilson@mastodon.social avatar

I want to see if it's possible to replace runtime reflection in @xunit v3 with source generators (for better performance and to support NativeAOT), but I think I've already hit the first blocking point: no support for ? Only and ?

KirillOsenkov,
@KirillOsenkov@mastodon.social avatar

@bradwilson @xunit instead of Roslyn source generators you can have a regular MSBuild code generator that generates code during the build, and it can be any code and support C# and F# equally well. I often find that people use Roslyn source generators when all they want is any code generator.

KirillOsenkov,
@KirillOsenkov@mastodon.social avatar
bradwilson,
@bradwilson@mastodon.social avatar

@KirillOsenkov @xunit You think I can completely remove all the reflection required for discovering and running tests with this?

KirillOsenkov,
@KirillOsenkov@mastodon.social avatar

@bradwilson @xunit hmm I don't know enough about your usage, and how you were planning to use Source Generators, just wanted to point out that in many cases where you don't really need to analyze the C# source you can get by without Roslyn. But in your case having access to the compilation and syntax trees might be required I think?

mihamarkic,
@mihamarkic@mastodon.social avatar

@KirillOsenkov @bradwilson @xunit What would be the difference against Roslyn ones? (besides support for F#). A cons is probably not running during design time?

KirillOsenkov,
@KirillOsenkov@mastodon.social avatar

@mihamarkic @bradwilson @xunit yes, not running on every keystroke in the IDE and not having access to the compilation and syntax trees/documents/semantic models

mihamarkic,
@mihamarkic@mastodon.social avatar

@KirillOsenkov @bradwilson @xunit So, basically, here are raw .cs files and do what you want during build?

KirillOsenkov,
@KirillOsenkov@mastodon.social avatar

@mihamarkic @bradwilson @xunit sure, or any other inputs you need. Granted, Roslyn Source Generators are great when you need to understand the .cs files, but in many cases I've seen them abused to just generate .cs files out of say .xml or .json, without the need to understand .cs. If you want to generate C# you may not need source generators, but if you want to read or understand C# you probably need them (unless you host Roslyn yourself and pay the perf penalty of reading the project twice)

mhutch,
@mhutch@mastodon.social avatar
bradwilson,
@bradwilson@mastodon.social avatar

@mhutch @KirillOsenkov @mihamarkic @xunit I think in my case I'm going to need Roslyn because I need to inspect the source to do the generation (the simplest explanation is: I need a list of all methods in the project that are decorated with an attribute, so that I can bypass the need to find them via reflection at runtime, in order to support NativeAOT). I'm certainly going to investigate every option, though!

bradwilson,
@bradwilson@mastodon.social avatar

@mhutch @KirillOsenkov @mihamarkic @xunit (this time posted from the correct account 😂)

Funny historical fact: Jim and I created xUnit.net while working on CodePlex, so we were obviously the first internal adopters, but the first team outside of us that adopted xUnit.net internally was... Roslyn!

KirillOsenkov,
@KirillOsenkov@mastodon.social avatar

@bradwilson @mhutch @mihamarkic @xunit or perhaps you can run a task after Csc and reflect over the output binary at build time, then serialize your findings. This way you can support F# too.

mhutch,
@mhutch@mastodon.social avatar

@bradwilson @KirillOsenkov @mihamarkic @xunit

My post was targeted at generating source code based on files that are not source code, e.g. generate serialization wrappers for a json file or something. Doing it this way has similar perf and complexity as Roslyn generators, and if you use CodeDOM you can support every language with a CodeDOM provider.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • CSharp
  • kavyap
  • thenastyranch
  • GTA5RPClips
  • tester
  • InstantRegret
  • DreamBathrooms
  • ngwrru68w68
  • magazineikmin
  • everett
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • cisconetworking
  • megavids
  • khanakhh
  • normalnudes
  • osvaldo12
  • cubers
  • tacticalgear
  • Durango
  • ethstaker
  • modclub
  • anitta
  • provamag3
  • Leos
  • JUstTest
  • lostlight
  • All magazines