C# Reflection Explained (Claim generation example)

Поделиться
HTML-код
  • Опубликовано: 24 авг 2024
  • In this c# reflection tutorial I try to answer questions like: what is reflection? how to use reflection? how to solve problems with reflection? Primarily I try to shift your perspective to looking at your code as just another source of data which we manipulate using reflection. We then go to implement a real world example, where we generate all possible claims we would need and authorize based on generated claims.
    Patreon 🤝 / raw_coding
    Courses 📚 learning.raw-c...
    Shop 🛒 shop.raw-codin...
    Discord 💬 / discord
    Twitter 📣 / anton_t0shik
    Twitch 🎥 / raw_coding
    👉 Try Rider
    www.jetbrains....
    RD5K9-4TXXW-KMV3G-NYWSF-3ZSTP
    Source: github.com/T0s...
    #csharp

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

  • @danielkrajnik3817
    @danielkrajnik3817 2 года назад +38

    I miss dislike button

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

      Like this comment to dislike

    • @danielkrajnik3817
      @danielkrajnik3817 2 года назад +11

      @@RawCoding simple explanation that worked for me is that reflection is just reading a section of metadata, which .NET adds to compiled assemblies

    • @danielkrajnik3817
      @danielkrajnik3817 2 года назад +14

      having this comment pinned is the real self-reflection

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

      Thank you for sharing an explanation that clicked for you

    • @faanross
      @faanross 6 месяцев назад +2

      subbed just cause you pinned this comment, a man with intellectual humility.

  • @evrame.microwize
    @evrame.microwize 2 года назад +14

    Thank you very much for the time and effort you put for people to learn. Obviously not a lot of people understand how hard it is to acquire the knowledge you have digested and shared to the community in such a great way. Again, thanks and keep up the awesome work!

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

    Always wanted to take a closer look into reflection. I will take a look at the video later today, thanks for posting!

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

    Dude. That pad is Amazing. Scoping into classes looks very nice. Good job sharing that

  • @user-vz6tq8bl9k
    @user-vz6tq8bl9k 3 года назад +4

    Dude, awesome video... One of that moments that resets your self-estimation as a programmer back to a first-grader

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

      Haha yea I don’t think that ever stops

    • @user-vz6tq8bl9k
      @user-vz6tq8bl9k 3 года назад

      @@RawCoding for sure)

  • @joshuawiley6506
    @joshuawiley6506 4 года назад +4

    Amazing, I gel with your vibe. thanks dude. I appreciate it.

  • @shanksatutube
    @shanksatutube 4 года назад +6

    Hi, Thanks Anton for all the awesome content on your channel. Which LinqPad extension did you use for ConvertTo() ? Also, how did you gain some much knowledge in C#? any recommendations ?

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

      public static T ConvertTo(this string @this) => JsonSerializer.Deserialize(@this);
      and just practice :)

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

      @@RawCoding thanks dude

  • @B4RN154N
    @B4RN154N 2 года назад +2

    This was really eye opening for me. Thank you very much sir!

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

      Thank you for watching))

  • @marsdriver2501
    @marsdriver2501 Год назад +1

    literally Charlie the moist critical, but a programming youtuber

    • @RawCoding
      @RawCoding  Год назад +1

      Wooohooo! yeaaaah baby!

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

    This is so great!! I am going to add to watchlist to watch it again...

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

    Watched a couple of your videos and Subscribed just now!

  • @dennispitadeniya2479
    @dennispitadeniya2479 5 месяцев назад

    Good one brother

  • @nonameiskickass1319
    @nonameiskickass1319 3 года назад +2

    real genius indeed

  • @SpicyMelonYT
    @SpicyMelonYT 3 года назад +2

    Ok that intro and that phrasing was literally all I needed to immediately know that this was gonna be a great explanation. Its like you can read my mind in the beginning wth.
    Edit: After watching it all I was genuinely shocked at the similarities of how our minds work. I explain things just like you do and now I realize why people find it hard to understand me sometimes haha. I understood you though. Your explanation was basically 80% abstract thought and 20% communicational conventions (i.e. what we all agree on when we say words). I really wish there was a way to just send abstract thought over to someone else instead of trying to compress it down into words.

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

      Really appreciate your comment thank you 🙏

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

    Very informative video, cheers for creating them

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

      Thank you for watching:)

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

    hi thank you for this but could you please make full tutorial on lamda, func, ,anonymous method and event

  • @jimh3595
    @jimh3595 3 месяца назад

    Good stuff.

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

    Amazing videos, thank you

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

      Thank you for watching

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

    thanks man for great video

  • @alkiro_ra
    @alkiro_ra 10 месяцев назад +1

    Bruh. I'm too dump() for this

  • @rakshithnsachar1270
    @rakshithnsachar1270 2 года назад +2

    I wish I could have a tutor like you. Thank you for the work ur putting into.

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

      Thank you for watching

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

    seems like getting project for a Coursework that involves reflection wasn't the best idea

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

    IMO, i mean when Reflection does click for you, this video will make more sense.

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

      what would you say is missing from this video?

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

    Awsome video, thanks

  • @charlesoto2
    @charlesoto2 Год назад +1

    Why so many "\" in that json format?

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

      that's what json is gotta escape the " to not close of the string

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

    Hi, I'm getting this error "CS1061 'string' does not contain a definition for 'ConvertTo'"

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

    Damn, when excatly are you explaining what is the reflection? I watched the whole video carefully and I feel like I missed something because it ended and I still don't know what the reflection is exactly :/

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

      Code is data, you’ve written a program and there is data you can extract from you program. Reflection is reading data about your program at runtime.

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

    Awesome Anton.
    Thank you.
    #professorrawcoding
    #raw_coding

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

      Cheers :) Remember that thing I was talking about automatically generating claims? This is basically it

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

      @@RawCoding Yes I remember.
      Trust me, in time you/raw_coding is going to be the goto for all developers using the development stack that you have knowledge of.
      You will soon have no time for yourself : )

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

      @@RawCoding "Remember that thing I was talking about automatically generating claims?" Yes I remember very well.

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

      @@ricardothomas3779 I second that

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

    They way you typed it doesn't work for me. I had to use Single Quotes in the Split Parameter.
    "Hello World".Split(' ').Dump();

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

    14:45 I downloaded your code and it compiles. When I try the Startup(null) like you show it cannot find Startup. I added the WebApp.dll from Bin folder but it doesn't see any namespaces there.

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

      If you don’t have a payed version of LinqPad you need to add the namespace manually, press f4 and it’ll be there

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

      @@RawCoding Thanks I had tried that but my problem was I was not using LINQPad as your project is DotNet Core. Just got it working and continuing with video, Kindly!

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

      Ah alright

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

      @@RawCoding meant to say I wasn't running LINQPad 6. I bought the ultimate edition

  • @Antonio-lt1sp
    @Antonio-lt1sp 2 года назад +1

    This method .dump does not appear to me. What am I missing?

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

    Bro thanks for tour :) that was great, ı wonder about it was a show how we can do with reflection or it was a real scenario, I came here because I am looking something in reflection I would like put many of strings into one string with reflection, like property names are name1,name2, name3.. I dont know how much it is, when I read this from excel, I have to put all that to one list names

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

      Sorry I don’t quite understand

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

      Haha me too :) I dont know what I was trying to say, but I wonder about the auth claim with reflection is really needed or it is a show to see what we will do with using reflection

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

      It’s a demonstration

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

      @@RawCoding Okey, thanks for it. Reflection is really interesting :)

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

    Please make a video on Reflection.Emit if possible

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

      I never used it so I can't sorry :)

  • @tracetv8115
    @tracetv8115 4 года назад +3

    Great work and thank u so much for ur work! A video about marshaling would be nice.

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

      Haven’t done it before so I need to try it first :)

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

    Can this be achieved with razor pages

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

    Another great video, thanks for this! One thing is that I guess you could set "inherit" parameter to true of "GetCustomAttribute()" in order to get that "Authorize" attribute from the controller itself, instead of adding " || x.DeclaringType.GetCustomAttribute(authAttr) != null)".

  • @batek34
    @batek34 4 месяца назад

    Great explanation, but maybe write a script beforehand; this video could have been half of what it was.

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

    They call him Jesus of Programming xD

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

    Jeepers, is it like kind of hacker or reverse engineer?

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

      Nope, it’s code as data

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

    Crack

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

    Nice haircut

  • @mac19999x
    @mac19999x 3 года назад +2

    Where are you from? Your English is very good, but it sounds as a second language. Like something one would be taught at school.

  • @trudyreiser8075
    @trudyreiser8075 3 месяца назад

    You go way too fast