Advanced C#: 05 Reflection

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

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

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

    The explanations are so clear that I'm willing to forgive you for using the light mode.

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

    I'm glad I found this tutorial first, this is exactly what I needed to know. Thanks!

  • @LeskyAM
    @LeskyAM 8 лет назад +6

    Very good videos, all of them, I'm trying to refresh some C# skills after two years of doing nothing with it and your videos are helping me a lot. Even more, my first language is not English and I can understand you loud and clear. I stuck thinking in the minute 13 and I remembered that there is another difference between the use of the typeof operator and the GetType method, and it's that we can use GetType method only using instances of the types, whereas the typeof operator can be only used on the type itself.
    Great job, thanks for your time and effort.

  • @danielmafileo4078
    @danielmafileo4078 8 лет назад +3

    Good tutorial man, Java is my primary programming language and now i'm learning C# for two of my other papers. They are both similar in most areas however the more you learn about C#, you come across new concepts like Attributes, Delegates, Events and Reflections which are all new & confusing but they have their use. Hope to understand these concepts more and you are doing a great job on explaining these C# concepts. God bless! :D

  • @kaptnhartkor8549
    @kaptnhartkor8549 6 лет назад +2

    It's a pleasure to listen to this, thank you for sharing.

  • @Suamere
    @Suamere 9 лет назад +1

    I think it's good to note a paradigm you go through which is a common paradigm when working with reflection:
    You frequently use reflection to work through some variables and set up a type of structure in variable-form which represents what you want to do. For example, you get a type, you reflect on its members, you select a property or method. And that is all just plain'ol'reflection.
    But what ends up happening is that you then need an INSTANCE to apply your reflection template to. Part one is just mapping out what kind(s) of type(s) and how their members are structured and the type of data you may want to invoke or read from. Part two is to give an instance of matching implementation to your structure so that getting-value or invoking-members actually becomes meaningful.
    Understanding those two separate parts helps to use reflection in my mind.

  • @mhamdaoui4853
    @mhamdaoui4853 6 лет назад +3

    man, you are the best teacher ever. Thank you so much. Thump up + subscribed

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

    I was hanging about using reflection :D, your video was great and I understood the concept. Thank you!

  • @100F-p3h
    @100F-p3h 6 лет назад

    Really helpful and concise tutorial as well as a clear explanation of reflections. Thanks Clint!

  • @lucasdotnet
    @lucasdotnet 5 лет назад

    You are an amazing instructor!

  • @goshiri
    @goshiri 5 лет назад +3

    You sound like Saul Goodman from "Better Call Saul", Thanks!

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

    Thank you so much, It will be very helpful to create frameworks. I am not pro in C# but I understood clearly. Liked the video and subscribed

  • @manjeetnandal1
    @manjeetnandal1 5 лет назад

    Great sharing!
    Many useful!
    Great thanks!

  • @Layarion
    @Layarion 4 года назад +5

    i really don't understand, why not just you know...run the method the normal way?

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

      Frameworks

  • @VJPaz
    @VJPaz 8 лет назад

    Good point, especially when are working with Generics, Reflection is very useful. I think EF also uses Reflection behind the scene.

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

    Great explanation! Thank you

  • @user-rp9iis1en6h
    @user-rp9iis1en6h 4 года назад +1

    What is the benefit of reflection, why would we use that in our code knowing it needs to write more code?

  • @stanvalentin6635
    @stanvalentin6635 6 лет назад +1

    Why those guys from Microsoft can't explain in their videos like you do ? Good job!

  • @theesunnlightt2268
    @theesunnlightt2268 7 лет назад

    man you are the best .... thanks a lot .... please keep it up

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

    I'm a little bit confused by the ".Count()" call in "type.GetCustomAttribute().Count()". Does that mean a type can have multiple times the same atttribute?

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

    Fudging awesome! Thanks

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

    how does this work with protected and private methods though?

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

    What are the things that you put inside of your custom AttributeClass?

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

    how do you resist the light mode

  • @Liz4rdMan
    @Liz4rdMan 7 лет назад

    First of all I want to say that your videos are awsome, you are confident, you explain it clearly and you know exactly what you want to do.
    Second, I understood what you are doing, however I did not understand why you are doing it. It feels like you are itching your left ear with your right hand. Why would you execute a method through the reflection if you can do it through the object you created? (just an example)

  • @darkroiii
    @darkroiii 5 лет назад

    good tutorial, i learned a lot. one thing is not clear for me though. How come the lambda returns the types or methods instead of a bool?

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

    deep dark fantasies

  • @0x544D
    @0x544D 5 лет назад

    Wonder if u actually can GetAnExternalExecutingAssembly ? that wuld be rly cool for reversing and stuff .

  • @carmelraj2158
    @carmelraj2158 7 лет назад

    Great Video. Thanks a lot

  • @CanuckRfn
    @CanuckRfn 10 лет назад

    Super fantastic brain candy. Thanks!

  • @FranMcOd
    @FranMcOd 9 лет назад

    hey, rlly cool, but how can i invoke the method Parse(String s) from double?

  • @yagneshcangi1086
    @yagneshcangi1086 10 лет назад +12

    You can use .Any() instead of .Count()>0

    • @N3PatHYA
      @N3PatHYA 9 лет назад

      Yagnesh Cangi please help with error
      Error 3 The non-generic method 'System.Reflection.MemberInfo.GetCustomAttributes(System.Type, bool)' cannot be used with type arguments

    • @Suamere
      @Suamere 9 лет назад +3

      +Yagnesh Cangi Shh... he isn't to Linq yet. Lol.

  • @adipopik4
    @adipopik4 7 лет назад

    great tutorial!

  • @maringeorgiev4456
    @maringeorgiev4456 9 лет назад

    Can you provide the code, please?

  • @morphman86
    @morphman86 9 лет назад +2

    This is all cool and stuff, but what's the benefit of retrieving the type of Sample and invoke the method through the type, with the variable sample specified, through Reflections, rather than just go "sample.MyMethod();"?
    Attributes I get, but the rest of this tutorial's content just seems like extra steps, that cost more resources, to do something that could be done a lot easier.

    • @Suamere
      @Suamere 9 лет назад +9

      +morphman86 Long-Story short: Reflection is bad mkay.
      Of course, like all tools in our toolbox, some of them are necessary sometimes. Sort of like the Star-Screwdriver. You rarely need to use it, but you should have one... and some people use them for everything even though they have a dam hammer right next to them.. STOP USING YOUR STAR-SCREWDRIVER AS A HAMMER!!!!.
      Sometimes you have no clue whatsoever about what classes you are using. Take .NET Web API For example:
      If I wanted to create some documentation or auto-implementation of some of my ApiControllers... but developers are constantly adding, removing, and altering the ApiControllers, I cant very well have hard-coded implementations for every single one. There could be anywhere from one to a hundred and they constantly change.
      So instead I use reflection to get the Assembly that contains my ApiControllers... then I get all classes that Implement ApiController... then I can continue on from there.
      Using this method, I could very powerfully create utility libraries that help me organize and construct code.
      Granted: I havent personally ever used reflection to handle Majorly Main-stream business logic. Though I do use it frequently for code maintenance, DLL Injection, and other fun stuff. What if MY Application wanted to open up a copy of a form in YOUR Application... I can use reflection to load in your Assembly and pull out what I want.
      Muy Importante... but not used as much as a hammer.

    • @morphman86
      @morphman86 9 лет назад

      Suamere Thank you, I think I understand now.
      Also, I think I should get a hammer and stop using my star-screwdriver for nails...

    • @Cmppayne26542
      @Cmppayne26542 7 лет назад

      Reflection is great for more advanced things like dependency injection. With it you can do complex things like auto initialize all classes that inherit an interface dynamically based off the namespace. So instead of configuring the container to add the class each time you make a new one, reflection will automatically add it to the container as long as it meets the condition you provided.

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

    I was hoping you'd also cover reflection.Emit, but great video anyways, Thanks!

  • @rakeshgaur6637
    @rakeshgaur6637 10 лет назад +4

    Hey thanks a ton... if anyone having error in attribute calling try
    var types = assembly.GetTypes().Where(a => a.GetCustomAttributes(typeof(MyClassAttribute), false).Count() > 0);

    • @N3PatHYA
      @N3PatHYA 9 лет назад

      Rakesh Gaur i got error . please help
      Error 3 The non-generic method 'System.Reflection.MemberInfo.GetCustomAttributes(System.Type, bool)' cannot be used with type arguments

  • @NikhilKumar-nc1md
    @NikhilKumar-nc1md 7 лет назад

    For fetching specific type you are using Attributes and Genrics But in Reflection also you can get it by : var sampleType=typeof(Sample);
    What's the benifit of generics and Attributes over this ?

  • @brettsullivan4025
    @brettsullivan4025 10 лет назад

    get juice rocked!!!!!!!!!!!!!!!!

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

    Invoke have NullReferenceException