How to write better code in C# using Source Code Analyzers (Roslyn)

Поділитися
Вставка
  • Опубліковано 31 лип 2024
  • Become a Patreon and get source code access: / nickchapsas
    Check out my courses: dometrain.com
    Hello everybody I'm Nick and in this video I will talk about source code analyzers also known as Roslyn analyzers. I will explain what they are, how they work, the forms they can have and how you can use them to write cleaner, better and safer code.
    Timestamps
    What are Roslyn Analyzers - 0:00
    Detecting closures and saving memory - 4:05
    Writing safer reflection code - 8:31
    Don't forget to comment, like and subscribe :)
    Social Media:
    Follow me on GitHub: bit.ly/ChapsasGitHub
    Follow me on Twitter: bit.ly/ChapsasTwitter
    Connect on LinkedIn: bit.ly/ChapsasLinkedIn
    Keep coding merch: keepcoding.shop
    #roslyn #csharp #analyzers

КОМЕНТАРІ • 53

  • @nickchapsas
    @nickchapsas  3 роки тому +15

    I forgot to mention it in the video but you can find more Roslyn analyzers here: github.com/Cybermaxs/awesome-analyzers
    You can also search for "Roslyn analyzers GitHub" and you will find the most popular ones. People are creating some really good stuff. Don't forget to star their GitHub repos.
    - Keep Coding

    • @GregWilliamBryant
      @GregWilliamBryant 3 роки тому

      Hello Nick, further video creating analyzers would be awesome. Also, Rider centric tutorial would be good, as the one's I have seen have been Visual Studio-based. Further, some areas I would personally find helpful are how to efficiently distribute them with your solution (I'm guessing Nuget is the way forward here) and the foibles of how Rider interacts with Analyzers and it's own built-in one, code cleaning rules etc. I've found that this is one area the Rider has a fairly messy implementation on this front. Also, that touches on my final interest, do you have any best practices for distributing common code inside your organisation. I've seen Nuget suggested and equally frowned upon for this.

  • @vocabulary_builder
    @vocabulary_builder 3 роки тому +38

    Roslyn analyzers are like Grammarly for coders.

    • @janne_kekalainen
      @janne_kekalainen 3 роки тому +1

      So true.

    • @awesomesauce804
      @awesomesauce804 2 роки тому +1

      so I'll be even better at copy/paste? Perfect. I'm not looking to increase my fundamental knowledge but instead to skate by at my day job being overpaid the entire time. It sounds like this is great for me, thanks for the feedback. /s

  • @JJayToKlamca
    @JJayToKlamca 3 роки тому +13

    Just discovered your channel. Your every video is a top notch material. Amazing work!

  • @thibaudgallanddemanneville174
    @thibaudgallanddemanneville174 3 роки тому

    Great video as always! I finally understood exactly what the enclosure is !

  • @lior279
    @lior279 3 роки тому

    Great work Nick, Lots of value in your videos.
    Yes I would like Roslyn analyzers videos.
    Also, can you elaborate about how and what for do you use reflection.

  • @tofraley
    @tofraley 2 роки тому

    Great video! Yes, I'd love to see one on how to write a source analyzer.

  • @sdasddsasadad2287
    @sdasddsasadad2287 3 роки тому

    Thanks! it really helped me to get started programming!!

  • @richardikin
    @richardikin 3 роки тому

    Absolutely fascinating!

  • @mystiqkc
    @mystiqkc 2 роки тому

    Excellent video!!

  • @irelandfpv
    @irelandfpv 3 роки тому

    Interesting topic. Never used it in live development yet.

  • @killpopers
    @killpopers 3 роки тому +2

    I'd love to see how to write analyzers please do a video on this

  • @carlosalarcon2737
    @carlosalarcon2737 3 роки тому +1

    Finally I found the video I wanted!! Thanks a lot!! Btw my rider in Linux shows reference not found when I compile (as a warning) but the alert is shown.

  • @Pedro5antos_
    @Pedro5antos_ 3 роки тому

    10:50 awesome content, mate!

  • @digitalphear1960
    @digitalphear1960 3 місяці тому

    There was a guy i met telling me about how hw makes boxes within boxes in C#. Now that sounds nice for a guy like me who can make boolean chip sets to accomplish 'almost' any task..
    most code seems to be the same set up overall
    true/fulse.
    Light-up/black-out
    cell groups. And.OR.XOR
    But all over the place wich compared to physical boards/chips that lead into one another.. you can see how it gets confusing for someone like me. The box within box sounds nice for keeping track of group and function with an intangible :D

  • @meirkr
    @meirkr 2 роки тому

    I would also appreciate having.a video about writing analyzars. Tx.

  • @khamid70
    @khamid70 2 роки тому

    Bravo, keep on

  • @roro1826
    @roro1826 3 роки тому +1

    I've been watching your vids for sometime now, I couldn't resist hitting the sub button for this vid

  • @nanvlad
    @nanvlad 3 роки тому +7

    Hi Nick. Thanks for this video. Can you share a list of useful source analyzers, like you showed in the video? Are there many of them?

    • @nickchapsas
      @nickchapsas  3 роки тому +4

      Ah damn I forgot to mention it on the video. There is a repo that contains a list of them here: github.com/Cybermaxs/awesome-analyzers but it's a bit outdated. It still contains many good ones.

  • @PhilippeMatray
    @PhilippeMatray 3 роки тому +2

    Hello Nick,
    In this video, you have shown 2 analyzers that are really interesting.
    Are there any others that you would recommend?

  • @atikhasan7714
    @atikhasan7714 3 роки тому

    Hello, Dear can you make a video tutorial about singleton, scope, and transient (which is better for.net core API)

  • @adityashinde1657
    @adityashinde1657 3 роки тому +2

    Please adjust the font size/zoom levels, to comfortably watch the content on big screens.

    • @Albileon
      @Albileon 3 роки тому +1

      Seems fine on my screen? Not having any issues.

    • @diegoronkkomaki6858
      @diegoronkkomaki6858 3 роки тому +1

      Nah this is perfect zoom and font size when watching on a mobile device.

  • @nataliasikorka4825
    @nataliasikorka4825 3 роки тому

    Hi Nick,
    I just watched your video about IHttpClientFactory and was wondering - should i dispose instance of HttpClient from factory like this:
    ```
    using var httpClient = httpClientFactory.CreateClient("Test");
    ```
    or it does not matter cause of some handling in IHttpClientFactory or even we shouldn't?
    Sorry that this is not in subject of this video, but it's the newest and there is bigger chance for reply ^^

  • @MrGuardianX
    @MrGuardianX 2 роки тому

    As of November 2021 your example with Reflections doesn't work. I mean the analyzer doesn't highlight this field anymore (v 0.3.0)

  • @zirexpl6395
    @zirexpl6395 3 роки тому

    I don't understand how to get that and use it. It's something like external software which u run during programming, or nuget package... Or maybe i should write it by myself. If there is answear
    yes" for all question, i would prefer a complete package of this instead of writing it by myself

  • @SimbaTheDogKing
    @SimbaTheDogKing 3 роки тому +1

    Can .NET analyzer/Roslyn analyzer be added to CICD pipeline?

    • @nickchapsas
      @nickchapsas  3 роки тому +1

      If it is installed as a Nuget package then yeah

  • @crazywill32
    @crazywill32 3 роки тому +1

    I see Nick uses "!." As and operator a lot. As I am still learning C#, what does this mean?

    • @nickchapsas
      @nickchapsas  3 роки тому +1

      It means that this value will definitely not be null. I’m using it to suppress the warning for the video. In a realistic scenario you might wanna handle null appropriately

    • @crazywill32
      @crazywill32 3 роки тому

      @@nickchapsas Thanks Nick!
      I have found the videos super insightful and interesting. As a professional in another field that codes for a small team, they point out things I should look into to be better.

  • @clearlyunwell
    @clearlyunwell 3 роки тому

    👍🏽

  • @petrzurek5713
    @petrzurek5713 3 роки тому +1

    Nick, which language do you like to use more, Kotlin or C#?

    • @nickchapsas
      @nickchapsas  3 роки тому +4

      I use C# waaaaay more. It's like a 95% C# 5% Kotlin. I only use Kotlin for personal random stuff and not for an actual professional purpose. I do enjoy it a lot though.

    • @petrzurek5713
      @petrzurek5713 3 роки тому

      @@nickchapsas Nice, thanks. Do you mostly write cross-platform .net core code these days or do you write windows specific stuff still (wpf, iis web apps, ...)

    • @nickchapsas
      @nickchapsas  3 роки тому

      @@petrzurek5713 crossplatform. I've only worked on windows specific stuff for 1 year right before .net core came out

  • @sohampatel1063
    @sohampatel1063 3 роки тому +2

    Pleas make video on how to mak custom analyzers and more and more❤️

  • @ahmedkhudhair8035
    @ahmedkhudhair8035 3 роки тому

    Can you write code that Cannot be decompile for security

    • @igorthelight
      @igorthelight 3 роки тому +1

      That's impossible as far as I know.
      You could make it much less readable tho.
      Also, ANY scripting language (C#, VB, Java, Kotlin, JS, Python... ) is a bad idea if you are concerned about your code security.

    • @sohampatel1063
      @sohampatel1063 3 роки тому

      As far i know only c++ makes it hard to reverse engineer the code.

    • @ahmedkhudhair8035
      @ahmedkhudhair8035 3 роки тому

      @@igorthelight can you make video on reverse engineering in .net

    • @igorthelight
      @igorthelight 3 роки тому +2

      @@sohampatel1063 Not only C++ but ALL programming languages that produce native binaries (C, C++, Rust, COBOL, Fortran, Pascal, Kotlin Native...)

    • @igorthelight
      @igorthelight 3 роки тому

      @@ahmedkhudhair8035 Sadly, I can't say that I'm professional enough to make a video.
      But I may recommend to try "Telerik JustDecompile", "JetBrains dotPeek" and "ILSpy".
      Just play around with them and you will be able to decompile most .NET programs. To decompile more professional programs you will need more knowledge (Google Search is a good tool ;-) )

  • @weluvmusicz
    @weluvmusicz 3 роки тому +7

    Make an analyzer that prevents my colleagues from using foreign language words instead of english in source code.

  • @pawetarsaa9904
    @pawetarsaa9904 2 роки тому

    You missed the opportunity to type ANALyzer

  • @canabale
    @canabale 6 місяців тому

    I am honestly very disappointed in this Video... I was actually expecting to see some actual code of an individual analyzer... not just examples for given ones...