Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CustomClassAttribute
- {
- using System;
- public class CustomClassAttributeMain
- {
- public static void Main()
- {
- string command = Console.ReadLine();
- while (command != "END")
- {
- Type type = typeof(Weapon);
- object[] attributes = type.GetCustomAttributes(false);
- foreach (CustomAttribute attribute in attributes)
- {
- ExecuteCommand(command, attribute);
- }
- command = Console.ReadLine();
- }
- }
- private static void ExecuteCommand(string command, CustomAttribute attribute)
- {
- if (command == "Author")
- {
- Console.WriteLine($"Author: {attribute.Author}");
- }
- else if (command == "Revision")
- {
- Console.WriteLine($"Revision: {attribute.Revision}");
- }
- else if (command == "Description")
- {
- Console.WriteLine($"Class description: {attribute.Description}");
- }
- else if (command == "Reviewers")
- {
- Console.WriteLine($"Reviewers: {attribute.Reviewers}");
- }
- }
- }
- [CustomAttribute("Pesho", 3, "Used for C# OOP Advanced Course - Enumerations and Attributes.", "Pesho, Svetlio")]
- public class Weapon
- {
- }
- [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
- public class CustomAttribute : Attribute
- {
- public CustomAttribute(string author, int revision, string description, string reviewers)
- {
- this.Author = author;
- this.Revision = revision;
- this.Description = description;
- this.Reviewers = reviewers;
- }
- public string Author { get; }
- public int Revision { get; }
- public string Description { get; }
- public string Reviewers { get; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement