..

Co se deje pri prekladu

V .NET je nejaka sada trid, ktera umoznuje zkoumat metadata assemblies, ktere jsou nahrade v te CLR, ve ktere bezim.

Typ Type

Typ Assembly

Ma staticke metody, vsechny vraci nejakou instanci tridy Assembly

// Get types implementing ISimplisticRoutesHandler from the calling assembly
Type[] types = Assembly.GetCallingAssembly().GetTypes()
    .Where(t => t.GetInterfaces().Contains(typeof(ISimplisticRoutesHandler)))
    .ToArray();

Metody na instanci typu Assembly:

Metody na instanci typu Type vraci instance potomku abstraktni tridy Memberinfo

A obdobne veci jako

Co s tim?

Muzeme si zaridit python-like duck typing.

void RunMethod(object obj, object[] args, string methodName) {
    MethodInfo? method = obj.GetType().GetMethod(methodName);
    if (method != null) {
        method.Invoke(obj, args);
    }
}

Zajimave metody

var a = Activator.CreateInstance(typeof(A));
var m = aType.GetMethod(nameof(A.f));
m.Invoke(a, null);

Problemy reflection