csharp
csharp copied to clipboard
Implement new Concept Exercise: attributes
This issue describes how to implement the attributes concept exercise for the C# track.
Getting started
Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
Please also watch the following video:
Goal
The goal of this exercise is to teach the student the basics of the Concept of Attributes in C#.
Learning objectives
- Know what attributes are.
- Know the limitations of attributes.
- Know how to add attributes to values.
- Creating a custom attribute.
- Using the
AttributeUsageAttributeto restrict usage.
Out of scope
- Using reflection to read attributes.
Concepts
The Concepts this exercise unlocks are:
attributes: know what attributes are; know the limitations of attributes; know how to add attributes to values; creating a custom attribute.
Prequisites
This exercise's prerequisites Concepts are:
inheritance: know how to inherit from a class.
Any data types used in this exercise (e.g. strings) should also be added as prerequisites.
Resources to refer to
Hints
- Attributes: what attributes are and how to use them.
- Creating custom attributes: how to create custom attributes.
- Restricting attribute usage: how to restrict attribute usage.
After
- Attributes: what attributes are and how to use them.
- Creating custom attributes: how to create custom attributes.
- Restricting attribute usage: how to restrict attribute usage.
Representer
This exercise does not require any specific representation logic to be added to the representer.
Analyzer
This exercise does not require any specific analyzer logic to be added to the analyzer.
Implementing
To implement this exercise, please follow these instructions.
Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue.
Using reflection to read attributes.
I can't help feeling that if we don't allow attributes to be read not only will custom attributes seem rather pointless but the compiler and framework provided ones as well. We might have to pretty much give the code to access them but at least students would see the point of them.
I can't help feeling that if we don't allow attributes to be read not only will custom attributes seem rather pointless but the compiler and framework provided ones as well. We might have to pretty much give the code to access them but at least students would see the point of them.
Maybe we should have reflection as a prerequisite of this exercise? That way, we can use reflection here. I'd be hesitant to also introduce reflection here, or do you think that could work well?
Maybe we should have reflection as a prerequisite of this exercise?
The trade-off is complexity (of bringing in reflection either as part of exercise or a prerequisite) vs. leaving a bit of a mystery about what the point of attributes is. I too favour for having a separate reflection exercise. Our audience is seasoned programmers who should be able to handle plus it will give us an opportunity to tell those dynamic coder types that it exists to use it sparingly.
Excellent!