Challenge introduction
- [Instructor] Let's spend a minute talking about this challenge before you look at the challenge code itself. For most of this course, I've asked you to create an attribute and modify the attribute. And then my unit tests have verified that you met the requirements. And the way I did that is by writing reflection code. Now in this code challenge you will be writing reflection code. And why do we do this? Let's think about why we create custom attributes in the first place. The reason we do that is because we're building some developer tool. We're creating a custom attribute, and we're asking the other developers to apply our attribute to their classes, or their interfaces, or their methods. And then our tool will examine their .NET assemblies, find out if they've applied our attribute, and then read the property values on that attribute. So that's what I'm asking you to do here. In this example, you're going to get an instance of a collectible card passed into this method, check for unit test method. You're going to get this card, and you're going to look at all the methods on this card. You're going to see if any of those methods have the attribute applied. And if they do have the attribute applied, you're going to look at the timeout property, and you're going to read that value. Now, the way I'm going to test whether you've written the reflection code correctly is I'm going to ask you to put the timeout value in this list of int. So you're going to return that from this method. Now, you don't know how many of my methods actually have the attributes. So it could be zero methods, it could be one, it could be two. You need to figure that out. And then if the attribute is applied, then read that value and add it to a list of int and return that in this method, from this method, I should say. Now, there are other things that are interesting about this sample code that you're going to look at, is because of the way CoderPad works, and the way I have to write the unit test is I have created a partial collectible card class here. The real implementation of this collectible card is in the other partial class, which is in my unit testing code. And over there I will create the update value, the check inventory, and the validate check sum method, and I might apply the test method attribute to one or more of these methods. So have fun writing the reflection code, and I'll see you in the video where we talk about my solution.