C# Reflection Explained (Claim generation example)

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ต.ค. 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

    • @gitgudsec
      @gitgudsec 8 หลายเดือนก่อน +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!

    • @RawCoding
      @RawCoding  4 ปีที่แล้ว +1

      Hope it helps :)

  • @distinguishedmoments2277
    @distinguishedmoments2277 2 ปีที่แล้ว +1

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

    • @RawCoding
      @RawCoding  2 ปีที่แล้ว

      Glad you like 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

  • @joshuawiley6506
    @joshuawiley6506 4 ปีที่แล้ว +4

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

  • @IvanKriuchkov
    @IvanKriuchkov 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

    • @IvanKriuchkov
      @IvanKriuchkov 3 ปีที่แล้ว

      @@RawCoding for sure)

  • @B4RN154N
    @B4RN154N 3 ปีที่แล้ว +2

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

    • @RawCoding
      @RawCoding  3 ปีที่แล้ว

      Thank you for watching))

  • @swapnilpakolu5817
    @swapnilpakolu5817 2 ปีที่แล้ว

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

  • @abuzeromohammed3386
    @abuzeromohammed3386 4 ปีที่แล้ว +7

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

  • @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 🙏

  • @marsdriver2501
    @marsdriver2501 ปีที่แล้ว +1

    literally Charlie the moist critical, but a programming youtuber

    • @RawCoding
      @RawCoding  ปีที่แล้ว +1

      Wooohooo! yeaaaah baby!

  • @nonameiskickass1319
    @nonameiskickass1319 3 ปีที่แล้ว +2

    real genius indeed

  • @LarryPeteet
    @LarryPeteet 4 ปีที่แล้ว +1

    Watched a couple of your videos and Subscribed just now!

    • @RawCoding
      @RawCoding  4 ปีที่แล้ว

      Awesome thank you

  • @alkiro_ra
    @alkiro_ra ปีที่แล้ว +1

    Bruh. I'm too dump() for this

  • @vasugupta1
    @vasugupta1 4 ปีที่แล้ว +1

    Very informative video, cheers for creating them

    • @RawCoding
      @RawCoding  4 ปีที่แล้ว

      Thank you for watching:)

  • @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.

  • @mohamedfared9659
    @mohamedfared9659 3 ปีที่แล้ว +1

    thanks man for great video

  • @parsalotfy
    @parsalotfy 3 ปีที่แล้ว +1

    Amazing videos, thank you

    • @RawCoding
      @RawCoding  3 ปีที่แล้ว

      Thank you for watching

  • @timmayabi7734
    @timmayabi7734 2 ปีที่แล้ว

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

  • @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 :)

  • @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)".

  • @paulofernandoee
    @paulofernandoee 2 ปีที่แล้ว

    Awsome video, thanks

  • @jimh3595
    @jimh3595 5 หลายเดือนก่อน

    Good stuff.

  • @LarryPeteet
    @LarryPeteet 4 ปีที่แล้ว +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  4 ปีที่แล้ว

      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 4 ปีที่แล้ว +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  4 ปีที่แล้ว +1

      Ah alright

    • @LarryPeteet
      @LarryPeteet 4 ปีที่แล้ว

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

  • @dennispitadeniya2479
    @dennispitadeniya2479 7 หลายเดือนก่อน

    Good one brother

  • @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

  • @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 :)

  • @Antonio-lt1sp
    @Antonio-lt1sp 2 ปีที่แล้ว +1

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

    • @RawCoding
      @RawCoding  2 ปีที่แล้ว +1

      Its LinqPad only

    • @Antonio-lt1sp
      @Antonio-lt1sp 2 ปีที่แล้ว

      @@RawCoding thanks!

  • @marsdriver2501
    @marsdriver2501 ปีที่แล้ว

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

  • @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

  • @charlesoto2
    @charlesoto2 2 ปีที่แล้ว +1

    Why so many "\" in that json format?

    • @RawCoding
      @RawCoding  2 ปีที่แล้ว

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

  • @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?

  • @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

  • @LarryPeteet
    @LarryPeteet 4 ปีที่แล้ว +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();

  • @xieweiling7543
    @xieweiling7543 3 ปีที่แล้ว +1

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

    • @RawCoding
      @RawCoding  3 ปีที่แล้ว

      Nope, it’s code as data

  • @Raveyboi
    @Raveyboi 3 ปีที่แล้ว +1

    They call him Jesus of Programming xD

  • @batek34
    @batek34 6 หลายเดือนก่อน

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

  • @jorgellanque7704
    @jorgellanque7704 ปีที่แล้ว

    Crack

  • @vetald1979
    @vetald1979 3 ปีที่แล้ว +1

    Nice haircut

  • @mac19999x
    @mac19999x 4 ปีที่แล้ว +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.

    • @RawCoding
      @RawCoding  4 ปีที่แล้ว

      I am from Latvia

  • @trudyreiser8075
    @trudyreiser8075 5 หลายเดือนก่อน

    You go way too fast