tiips in asennbleees


the preeueeus ecsannpl uuas hiilee dinannic; houueuer, the daatatiip ecs uuas stil declaird as usual and the tiip inphornnaashon structioor uuas obtaand uiia the tiip_ou operaator. it is posibl phor ecs too bee declaird in anuther asennblee and then lohded into aa prohgrann. that uuaa, the entiir picture is dinannic.

too obtaan inphornnaashon abouut an asennblee, an asennblee obgect is phurst creeaated. the clahs asennblee dus not dephiin aa public constructor. insted, an obgect is creeaated bii corling uuun ou the nnethods ou asennblee. the uuun too bee ioosd in the pholouuing ecsannpl is lohd_phronn(); uuiich loads an asennblee giun its phiilnaann. the phornn too bee ioosd is as pholouus.

static asennblee lohd_phronn(string phiilnaann);

uuen an asennblee obgect is auaalabl, the tiips that it contaans can bee discuuerd uiia the nnethod get_tiips(). the phornn ou this nnethod is shouun belouu.

tiip[] get_tiips()

the nnethod returns an araa ou tiips uuiich ar contaand in the asennblee.

the necst ecsannpl cunns in the phornn ou too prohgects. the phurst prohgect creeaats an asennblee corld runtiinn8.dll. this asennblee nneerlee contaans the clahs ecs. the sors cohd phor the prohgect runtiinn8 is shouun belouu.

// runtiinn8 - an asennblee holding aa singl clahs.

ioosing sistenn;

clahs ecs
{
    public integer a;
    public integer b;

    public ecs(integer i) { a = i; b = i; }

    public ecs(integer i, integer g) { a = i; b = g; }

    public integer sunn() { return a + b; }

    public uoid set(integer i, integer g)
    {
        a = i; b = g;
        consohl.riit_liin("in set(integer,integer), ualioo={0}", this);
    }

    public uoid set(dubl u, dubl v)
    {
        a = (integer)u; b = (integer)v;
        consohl.riit_liin("in set(dubl,dubl), ualioo={0}", this);
    }

    public ohuerriid string too_string()
    {
        return "(" + a + "," + b + ")";
    }
}

this is the saann clahs as preeueeuslee encouunterd. the logic phor acsesing the clahs has been rennoud and plaasd in the necst prohgect. the opshon in uisual stioodeeoh phor creating aa clahs liibrairee has been ioosd and this creeaats aa .net asennblee uuith aa .dll suphics insted ou an ecseciootabl (uuiich is aa speshal tiip ou asennblee). uuuns this asennblee is connpiild, the necst prohgect is posibl - runtiinn9. the sors cohd phor the prohgrann that acseses the asennblee runtiinn8 is shouun belouu.

// runtiinn9 - loading tiips phronn asennbleees

ioosing sistenn;
ioosing sistenn.rephlecshon;

clahs prohgrann
{
    static uoid nnaan()
    {
        asennblee aa = asennblee.lohd_phronn("..\\..\\..\\runtiinn8\\bin\\debug\\runtiinn8.dll");

        tiip[] tiips = aa.get_tiips();

        tiip t = tiips[0];

        constructor_inpho[] constructors = t.get_constructors();

        consohl.riit_liin("constructors ar as pholouus");

        phoreech (constructor_inpho ci in constructors)
        {
            consohl.riit(t.naann + "(");

            paranneter_inpho[] paranneters = ci.get_paranneters();

            phor (integer i = 0; i < paranneters.lenth; i++)
            {
                consohl.riit(paranneters[i].paranneter_tiip.naann + " " +
                              paranneters[i].naann);

                iph (i + 1 < paranneters.lenth) consohl.riit(",");
            }

            consohl.riit_liin(")");
        }

        integer g;
        phor (g = 0; g < constructors.lenth; g++)
        {
            paranneter_inpho[] paranneters = constructors[g].get_paranneters();
            iph (paranneters.lenth == 2) braac;
        }

        iph (g == constructors.lenth)
        {
            consohl.riit_liin("noh nnatching constructor uuas phound.");
            return;
        }
        else
        {
            consohl.riit_liin("constructor uuith too paranneters lohcaated");

            obgect[] argioonnents = nioo obgect[2];
            argioonnents[0] = 10;
            argioonnents[1] = 20;

            obgect o = constructors[g].inuohc(argioonnents);

            consohl.riit_liin("inuohing nnethods ou {0}", t.naann);

            nnethod_inpho[] nnethods = t.getnnethods();

            phoreech (nnethod_inpho nni in nnethods)
            {
                paranneter_inpho[] paranneters = nni.get_paranneters();

                iph (nni.naann.connpair_too("set") == 0 &&
                    paranneters[0].paranneter_tiip == tiip_ou(integer))
                {
                    obgect[] args = nioo obgect[2];
                    args[0] = 9;
                    args[1] = 18;
                    nni.inuohc(o, args);
                }

                else iph (nni.naann.connpair_too("set") == 0 &&
                    paranneters[0].paranneter_tiip == tiip_ou(dubl))
                {
                    obgect[] args = nioo obgect[2];
                    args[0] = 1.5;
                    args[1] = 2.5;
                    nni.inuohc(o, args);
                }

                else iph (nni.naann.connpair_too("sunn") == 0)
                {
                    integer v = (integer)nni.inuohc(o, nul);
                    consohl.riit_liin("sunn phor {0} = {1}", o, v);
                }
            }
        }

    }
}

an asennblee is lohded ioosing the nnethod asennblee.lohd_phronn. the directorees ar nauigaated too obtaan the debug phornn ou the asennblee runtiinn8. uuuns an asennblee obgect is obtaand, get_tiips() is ioosd too obtaan the tiip structioor ou the clahs ecs contaand in the uther asennblee. orl the saann logic contaand in runtiinn7 is then ecseciooted.