Cvičení - statická reflexe

Reflexe

SSŠVT


Cvičení - statická reflexe

Zadání

Napište konzolový program (ClassDecompiler), který zobrazí metadata o vybrané třídě. Vzhledově bude výsledek vypadat jako definice třídy v C#.

Stačí, když program zobrazí úroveň bloku s názvem třídy. A v tomto bloku budou (odsazené) definice konstruktorů, vlastností a metod. Všechny členy třídy stačí veřejné. Nemusíte hledat protected, internal, private apod.

Jednoduché datové typy můžete zobrazit buď v jejich .NET podobě (např. String, Boolean, Int32), nebo v podobě built-in types v C# (string, bool, int).

Příklad, jak bude výpis vypadat, je dole. Byla použita třída System.Net.Cookie.

public class Cookie
{
    // Konstruktory.
    public Cookie();
    public Cookie(string name, string? value);
    public Cookie(string name, string? value, string? path);
    public Cookie(string name, string? value, string? path, string? domain);

    // Vlastnosti.
    public DateTime TimeStamp { get; }
    public bool Secure { get; set; }
    public string Port { get; set; }
    public string Path { get; set; }
    public string Name { get; set; }
    public bool HttpOnly { get; set; }
    public DateTime Expires { get; set; }
    public string Domain { get; set; }
    public string Value { get; set; }
    public bool Discard { get; set; }
    public Uri? CommentUri { get; set; }
    public string Comment { get; set; }
    public bool Expired { get; set; }
    public int Version { get; set; }

    // Metody.
    public bool Equals(object? comparand);
    public int GetHashCode();
    public string ToString();
}