C# Expression Trees Explained (Reading/Creating Examples)

Поделиться
HTML-код
  • Опубликовано: 1 фев 2025

Комментарии • 71

  • @soixantelly
    @soixantelly 3 года назад +14

    hands down this channel is a youtube gem, the stuff that you don't know where to find to learn them, you find them here

  • @rohitarora92
    @rohitarora92 4 года назад +9

    Wherever others leave off in videos from other channels, Raw Coding starts from there!

  • @stefan-d.grigorescu
    @stefan-d.grigorescu 2 года назад +3

    Literllay the only video that keeps solving my problems related to Expressions! Thank you!

  • @Ram92026z
    @Ram92026z 2 года назад +4

    The ONLY video that helped me understand such a hard topic. Thanks!!

  • @babakabbasi5466
    @babakabbasi5466 Год назад +4

    I should thank you sir for such clear and concise explanations.👍

  • @kalka79
    @kalka79 3 года назад +1

    The best video on expression trees I have watched . Highly appreciated. cheers !

  • @emmanueladebiyi2109
    @emmanueladebiyi2109 9 месяцев назад

    Great intro into expression trees. Trust you to make the hard stuff easy 🙌🏼

  • @nadeemkh100
    @nadeemkh100 3 года назад +5

    Thank you man, you really a hero.

  • @KhanhNguyen-pq6kn
    @KhanhNguyen-pq6kn 4 года назад +1

    Another really really useful video, you re my google today, many thanks :D

    • @RawCoding
      @RawCoding  4 года назад

      Thank you for watching)

  • @matesebestyen3142
    @matesebestyen3142 4 года назад +1

    Loved the vid Mate, keep it up!

  • @Goygow
    @Goygow 3 года назад +1

    Amazing explanation, bro. Congrats.

  • @rongliao9255
    @rongliao9255 3 года назад +1

    Great tutorial! Thanks a lot!

    • @RawCoding
      @RawCoding  3 года назад

      Thank you for watching

  • @paikesitics
    @paikesitics 3 года назад +1

    Thanks man... this is realy a good explanation for me!

    • @RawCoding
      @RawCoding  3 года назад

      Thank you for watching

  • @stathispantazis2515
    @stathispantazis2515 3 года назад +1

    Pure gold man

  • @rezarezash
    @rezarezash 4 года назад +7

    Thank you very much for the video. Could we use the same approach to create a dynamic rule engine in c#? Something like some class, if, ( Name == "Test" and Age>20) then take some action? What I mean is, a rule engine editor where you define a rule body as mentioned and save it in DB and then load it and build the tree and run it on a type or collection and for every row meeting that criteria run the action defined in c#?

    • @RawCoding
      @RawCoding  4 года назад +1

      Yes some person goes in and configures a rule in a DSL and then you can resolve some handle that is possible :)

    • @StrikerJonny
      @StrikerJonny 4 года назад +2

      expression-json-serializer from aquilae or Serialize.Linq from esskar (both github repos) can serialize expressions.
      Never used them. But found them once.

    • @RawCoding
      @RawCoding  4 года назад

      Thank you for sharing!

    • @rezarezash
      @rezarezash 4 года назад

      @@StrikerJonny I think it is possible to save a postfix or prefix format of the rule in the DB and then load it parse it back as expression tree using stack. Just a guess!

    • @StrikerJonny
      @StrikerJonny 4 года назад +1

      @@rezarezash Sounds good.
      We do something similary at work, so our customers can build their own advanced search query. I dont know exaclty how we do that, but we use the saved expression to build an iqueryable, so efcore/db does the heavy load.

  • @TS-yf8hq
    @TS-yf8hq 2 года назад

    Great job 👏🏾

  • @senkamatic8448
    @senkamatic8448 4 года назад +1

    Thank you!!! You are the best))))

  • @tbgelectr0
    @tbgelectr0 2 года назад +1

    If I want to to create expression tree to sort on a generic child entity in Entity framework? It seems straightforward at first and the it explodes to something really really ugly...

    • @RawCoding
      @RawCoding  2 года назад

      So it does, make functions and name them. Your functions are the tools that you should assemble in to the final product

  • @aj.arunkumar
    @aj.arunkumar 3 года назад +1

    awesome awesome stuff

  • @انامسلموكفى
    @انامسلموكفى 2 года назад +1

    I have a calculator, it take the user input from the textbox and show the result in a label, i knew about the tree expression. But no idea how i do it dynamicly, could u help me please thank u for your great tuto
    EX: 1÷3+2-4×3+15

    • @RawCoding
      @RawCoding  2 года назад +1

      You don’t need to use expression trees for a calculator, create operations as classes, use composition pattern

  • @ahmadwasimgermany3393
    @ahmadwasimgermany3393 3 года назад +1

    Thanks so much for this tutorial so interessing however witch IDE You have used to edit the tree structure

    • @RawCoding
      @RawCoding  3 года назад +1

      LinqPad

    • @ahmadwasimgermany3393
      @ahmadwasimgermany3393 3 года назад

      @@RawCoding thank u so much i ve already got the answer from zooming im the left top coin from the application ;)

  • @RayanMADAO
    @RayanMADAO 2 года назад +1

    I don't understand how the accessor expression took a lowercase selectproperty string (word) and knew to get someClass.Word not someClass.word

    • @RawCoding
      @RawCoding  2 года назад

      I'd not get too hung up on it - it probably handles lower case stuff

  • @IMustHaveThatApe
    @IMustHaveThatApe 2 года назад +1

    Please for my sanity, why use this method over nameof()? I want to know real world applications for this so bad but i'm not sure this example is it, I hope you can prove me wrong

    • @RawCoding
      @RawCoding  2 года назад +1

      nameof is compile time, expressions are runtime

  • @milanstevic8424
    @milanstevic8424 Год назад

    14:20 god damnit unary isn't pronounced like uninstall, it's pronounced like unity
    also + is not an operand, + is a binary operator, it's binary because it depends on two operands
    likewise, a unary operator has a single operand
    conditional operator is also called a tertiary because it has three operands

  • @mfion1
    @mfion1 4 года назад +1

    Please can you reccomend a c# textbook

    • @RawCoding
      @RawCoding  4 года назад +7

      I’ve never read one so no sorry

    • @mfion1
      @mfion1 4 года назад +1

      @@RawCoding love your videos

    • @RawCoding
      @RawCoding  4 года назад

      Thanks :)

  • @nithinchandran7959
    @nithinchandran7959 4 года назад +2

    hangfire also does this

    • @RawCoding
      @RawCoding  4 года назад

      What exactly?

    • @nithinchandran7959
      @nithinchandran7959 4 года назад +1

      @@RawCoding In hangfire the Enqueue method expects an Expression as the parameter
      docs.hangfire.io/en/latest/background-methods/index.html

    • @RawCoding
      @RawCoding  4 года назад

      Thanks

  • @nhatquang3807
    @nhatquang3807 4 года назад +2

    Love your explanation and your style also :), but your audio volume is so low, even I have turned my audio level to the max.

    • @RawCoding
      @RawCoding  4 года назад

      Sorry about that, those were the times when I was still configuring my mic :P

  • @michaelblair5146
    @michaelblair5146 2 года назад

    Its not an operand, because an operand is a variable or value that an operator acts on. For example, a + is not an operand.

  • @DedmenMiller
    @DedmenMiller 4 года назад +2

    I think the first example isn't that good, just use nameof(User.Age)? Using functions just to get class members seems cumbersome and not really a real world use case.
    I think better example instead of just CreateUrl itself. Would've been a further function that runs code on a user.
    Based on the code it finds all the properties it needs for running the expression, to not request stuff it doesn't need.
    In this video you built something like CreateUrlFor(MyFunction)
    Where function takes user as argument and does stuff with it.
    I think a
    ExecuteWithData(MyFunction)
    Would be better.
    Where it iterates the whole MyFunction tree, and accumulates all properties on the User that are actually needed. Then generate url from that, request user, and execute MyFunction.
    That's a better real world use case I think.
    Don't need to show the actual http request and stuff, but I think that is a better to imagine use case.
    Hope my explanation makes sense, feels like it doesn't ^^

    • @RawCoding
      @RawCoding  4 года назад

      Mhm I think you missed the idea of the video, that we treat code as data, as long as you can see that it doesn’t matter what example I use.
      But I can’t remember what I said in the video exactly to reply properly sorry.
      But your example sounds exactly like what I would build it’s just there are time constraints on the video.

  • @muhammadzeshawn3883
    @muhammadzeshawn3883 2 года назад

    nameof(new user().age), nameof(new user().name) this is also not error prone

  • @davivify
    @davivify 2 года назад

    Unary is pronounced as in Unicycle, Universe, United. *Not* as in onion, undead, unhelpful.

  • @__alexfox__
    @__alexfox__ 4 года назад +1

    Сan i give you 100 likes? It was very helpful for me!

    • @RawCoding
      @RawCoding  4 года назад

      Of course you can! Glad I could help))

  • @jasonzuvela
    @jasonzuvela Год назад

    The audio glitches really kill my ears, with headphones