C# Reflection Explained (Claim generation example)

  Рет қаралды 44,493

Raw Coding

Raw Coding

4 жыл бұрын

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-coding.dev
Shop 🛒 shop.raw-coding.dev
Discord 💬 / discord
Twitter 📣 / anton_t0shik
Twitch 🎥 / raw_coding
👉 Try Rider
www.jetbrains.com/store/redeem/
RD5K9-4TXXW-KMV3G-NYWSF-3ZSTP
Source: github.com/T0shik/raw-coding-...
#csharp

Пікірлер: 93
@danielkrajnik3817
@danielkrajnik3817 2 жыл бұрын
I miss dislike button
@RawCoding
@RawCoding 2 жыл бұрын
Like this comment to dislike
@danielkrajnik3817
@danielkrajnik3817 2 жыл бұрын
@@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 жыл бұрын
having this comment pinned is the real self-reflection
@RawCoding
@RawCoding 2 жыл бұрын
Thank you for sharing an explanation that clicked for you
@faanross
@faanross 5 ай бұрын
subbed just cause you pinned this comment, a man with intellectual humility.
@evrame.microwize
@evrame.microwize 2 жыл бұрын
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 жыл бұрын
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 жыл бұрын
Hope it helps :)
@joshuawiley6506
@joshuawiley6506 4 жыл бұрын
Amazing, I gel with your vibe. thanks dude. I appreciate it.
@RawCoding
@RawCoding 4 жыл бұрын
Awesome!
@B4RN154N
@B4RN154N 2 жыл бұрын
This was really eye opening for me. Thank you very much sir!
@RawCoding
@RawCoding 2 жыл бұрын
Thank you for watching))
@swapnilpakolu5817
@swapnilpakolu5817 Жыл бұрын
This is so great!! I am going to add to watchlist to watch it again...
@distinguishedmoments2277
@distinguishedmoments2277 2 жыл бұрын
Dude. That pad is Amazing. Scoping into classes looks very nice. Good job sharing that
@RawCoding
@RawCoding 2 жыл бұрын
Glad you like it!
@LarryPeteet
@LarryPeteet 3 жыл бұрын
Watched a couple of your videos and Subscribed just now!
@RawCoding
@RawCoding 3 жыл бұрын
Awesome thank you
@vasugupta1
@vasugupta1 4 жыл бұрын
Very informative video, cheers for creating them
@RawCoding
@RawCoding 4 жыл бұрын
Thank you for watching:)
@shanksatutube
@shanksatutube 3 жыл бұрын
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 3 жыл бұрын
public static T ConvertTo(this string @this) => JsonSerializer.Deserialize(@this); and just practice :)
@shanksatutube
@shanksatutube 3 жыл бұрын
@@RawCoding thanks dude
@user-vz6tq8bl9k
@user-vz6tq8bl9k 3 жыл бұрын
Dude, awesome video... One of that moments that resets your self-estimation as a programmer back to a first-grader
@RawCoding
@RawCoding 3 жыл бұрын
Haha yea I don’t think that ever stops
@user-vz6tq8bl9k
@user-vz6tq8bl9k 3 жыл бұрын
@@RawCoding for sure)
@parsalotfy
@parsalotfy 3 жыл бұрын
Amazing videos, thank you
@RawCoding
@RawCoding 3 жыл бұрын
Thank you for watching
@paulofernandoee
@paulofernandoee 2 жыл бұрын
Awsome video, thanks
@abuzeromohammed3386
@abuzeromohammed3386 4 жыл бұрын
hi thank you for this but could you please make full tutorial on lamda, func, ,anonymous method and event
@RawCoding
@RawCoding 4 жыл бұрын
Sure :)
@SpicyMelonYT
@SpicyMelonYT 3 жыл бұрын
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 жыл бұрын
Really appreciate your comment thank you 🙏
@mohamedfared9659
@mohamedfared9659 3 жыл бұрын
thanks man for great video
@RawCoding
@RawCoding 3 жыл бұрын
Cheers
@rakshithnsachar1270
@rakshithnsachar1270 2 жыл бұрын
I wish I could have a tutor like you. Thank you for the work ur putting into.
@RawCoding
@RawCoding 2 жыл бұрын
Thank you for watching
@dennispitadeniya2479
@dennispitadeniya2479 5 ай бұрын
Good one brother
@timmayabi7734
@timmayabi7734 Жыл бұрын
Hi, I'm getting this error "CS1061 'string' does not contain a definition for 'ConvertTo'"
@marsdriver2501
@marsdriver2501 Жыл бұрын
literally Charlie the moist critical, but a programming youtuber
@RawCoding
@RawCoding Жыл бұрын
Wooohooo! yeaaaah baby!
@kyreehenry9202
@kyreehenry9202 2 жыл бұрын
Can this be achieved with razor pages
@jimh3595
@jimh3595 2 ай бұрын
Good stuff.
@tracetv8115
@tracetv8115 4 жыл бұрын
Great work and thank u so much for ur work! A video about marshaling would be nice.
@RawCoding
@RawCoding 4 жыл бұрын
Haven’t done it before so I need to try it first :)
@nonameiskickass1319
@nonameiskickass1319 3 жыл бұрын
real genius indeed
@RawCoding
@RawCoding 3 жыл бұрын
cheers :Da
@caglarcansarikaya1550
@caglarcansarikaya1550 2 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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)".
@RawCoding
@RawCoding 2 жыл бұрын
Thank you
@LarryPeteet
@LarryPeteet 3 жыл бұрын
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 жыл бұрын
@@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 жыл бұрын
Ah alright
@LarryPeteet
@LarryPeteet 3 жыл бұрын
@@RawCoding meant to say I wasn't running LINQPad 6. I bought the ultimate edition
@ricardothomas3779
@ricardothomas3779 4 жыл бұрын
Awesome Anton. Thank you. #professorrawcoding #raw_coding
@RawCoding
@RawCoding 4 жыл бұрын
Cheers :) Remember that thing I was talking about automatically generating claims? This is basically it
@ricardothomas3779
@ricardothomas3779 4 жыл бұрын
@@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 жыл бұрын
@@RawCoding "Remember that thing I was talking about automatically generating claims?" Yes I remember very well.
@hacao2739
@hacao2739 4 жыл бұрын
@@ricardothomas3779 I second that
@ProManKuba
@ProManKuba 2 жыл бұрын
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.
@sanjayi6245
@sanjayi6245 4 жыл бұрын
Please make a video on Reflection.Emit if possible
@RawCoding
@RawCoding 4 жыл бұрын
I never used it so I can't sorry :)
@marsdriver2501
@marsdriver2501 Жыл бұрын
seems like getting project for a Coursework that involves reflection wasn't the best idea
@Antonio-lt1sp
@Antonio-lt1sp 2 жыл бұрын
This method .dump does not appear to me. What am I missing?
@RawCoding
@RawCoding 2 жыл бұрын
Its LinqPad only
@Antonio-lt1sp
@Antonio-lt1sp 2 жыл бұрын
@@RawCoding thanks!
@LarryPeteet
@LarryPeteet 3 жыл бұрын
They way you typed it doesn't work for me. I had to use Single Quotes in the Split Parameter. "Hello World".Split(' ').Dump();
@RawCoding
@RawCoding 3 жыл бұрын
Mmmmm
@charlesoto2
@charlesoto2 Жыл бұрын
Why so many "\" in that json format?
@RawCoding
@RawCoding Жыл бұрын
that's what json is gotta escape the " to not close of the string
@paulsanchez5030
@paulsanchez5030 2 жыл бұрын
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?
@xieweiling7543
@xieweiling7543 3 жыл бұрын
Jeepers, is it like kind of hacker or reverse engineer?
@RawCoding
@RawCoding 3 жыл бұрын
Nope, it’s code as data
@alkiro_ra
@alkiro_ra 10 ай бұрын
Bruh. I'm too dump() for this
@Raveyboi
@Raveyboi 2 жыл бұрын
They call him Jesus of Programming xD
@RawCoding
@RawCoding 2 жыл бұрын
Hehe
@jorgellanque7704
@jorgellanque7704 Жыл бұрын
Crack
@vetald1979
@vetald1979 3 жыл бұрын
Nice haircut
@RawCoding
@RawCoding 3 жыл бұрын
Eyyy thanks
@batek34
@batek34 4 ай бұрын
Great explanation, but maybe write a script beforehand; this video could have been half of what it was.
@mac19999x
@mac19999x 3 жыл бұрын
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 3 жыл бұрын
I am from Latvia
@trudyreiser8075
@trudyreiser8075 2 ай бұрын
You go way too fast
C# Expression Trees Explained (Reading/Creating Examples)
36:43
Raw Coding
Рет қаралды 42 М.
C# Async/Await/Task Explained (Deep Dive)
24:22
Raw Coding
Рет қаралды 396 М.
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 29 МЛН
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 11 МЛН
Inside Out Babies (Inside Out Animation)
00:21
FASH
Рет қаралды 23 МЛН
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 9 МЛН
What is Span in C# and why you should be using it
15:15
Nick Chapsas
Рет қаралды 251 М.
See It In Action! C# Reflection for Beginners
11:33
Dev Leader
Рет қаралды 1,9 М.
JPEG is Dying - And that's a bad thing
8:09
2kliksphilip
Рет қаралды 39 М.
Where are types allocated in .NET and why people get it so wrong
14:35
C# Delegates & Lambdas Explained
32:43
Raw Coding
Рет қаралды 37 М.
What is C#? What is the difference between C# and .NET?
6:33
Interview Happy
Рет қаралды 80 М.
C# Channels Explained (System.Threading.Channels)
47:11
Raw Coding
Рет қаралды 36 М.
The weirdest way to loop in C# is also the fastest
12:55
Nick Chapsas
Рет қаралды 249 М.
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 29 МЛН