Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Zad2
- {
- [AttributeUsage(AttributeTargets.Class)]
- class WazneAttribute:Attribute
- {
- bool ważność;
- public WazneAttribute(bool ważność)
- {
- this.ważność = ważność;
- }
- public bool Ważność
- {
- get { return ważność; }
- }
- }
- [Wazne(true)]
- class Zadanie
- {
- public string nazwa;
- public string opis;
- public Zadanie(string nazwa, string opis)
- {
- this.opis = opis;
- this.nazwa = nazwa;
- }
- public override string ToString()
- {
- return $"{nazwa} to {opis}";
- }
- }
- [Wazne(false)]
- class Termin
- {
- string opis;
- DateTime data;
- public Termin(string opis, DateTime data)
- {
- this.opis = opis;
- data = new DateTime();
- }
- public override string ToString()
- {
- return $"{data} to {opis}";
- }
- }
- class Program
- {
- static void Podaj(object o)
- {
- Type p = o.GetType();
- object[] Attr = Attribute.GetCustomAttributes(p);
- foreach (object item in Attr)
- {
- if (item is WazneAttribute)
- {
- if ((((WazneAttribute)item).Ważność) == true)
- {
- Console.WriteLine(o.ToString()+" to wsm ważne");
- }
- else
- {
- Console.WriteLine(o.ToString()+" wywalone");
- }
- }
- }
- }
- static void Main(string[] args)
- {
- Zadanie z1 = new Zadanie("dupa", "pysior");
- Termin t1 = new Termin("mecz", DateTime.Now);
- Podaj(z1);
- Podaj(t1);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement