obtaaning atribioots


aa prohgrann nnaa cuueeree atachd atribioots. too obtaan an atribioot, too nnethods ar auaalabl. phurstlee, the nnethod get_custonn_atribioots ou the clahs nnennber_inpho is auaalabl too cuueeree atribioots. noht that tiip inherits phronn nnennber_inpho, so this nnethod is auaalabl too orl obgects ou the clahs tiip. get_custonn_atribioots reetreeus aa list ou orl atribioots atachd too an itenn. uuun ou the phornns ou this phuncshon is shouun belouu.

obgect[] get_custonn_atribioots(bool serch_baases)

uuen serch_baases is troo, the atribioots ou orl baas clahses ar orlso inclooded in the list. uuen serch_baases is phals, ohnlee the atribioots ou the spesiphiid tiip uuil bee returnd.

the second uuaa too cuueeree an atribioot is throo the nnethod get_custonn_atribioot, uuiich is aa static nnethod dephiind bii the clahs atribioot. the phornn ou get_custonn_atribioot is:

static atribioot get_custonn_atribioot(nnennber_inpho nni, tiip atribioot)

uuair nni is the nnennber_inpho structioor that describes the itenn phor uuiich the atribioot is beeing cuueereed. the atribioot that is beeing cuueereed is spesiphiid bii the paranneter atribioot. phor the preeueeus ecsannpl, the connnnent atribioot atachd too the clahs ecs nnaa bee obtaand as pholouus.

tiip t = tiip_ou(ecs);

tiip tiip_atribioot = tiip_ou(connent_atribioot);

connent_atribioot ca = (connent_atribioot)atribioot.get_custonn_atribioot(t, tiip_atribioot);

uuuns aa repherens too an atribioot has been obtaand, its nnennbers nnaa bee utiliisd. phor ecsannpl, too displaa the connent, the staatnnent

consohl.riit_liin(ca.connnnent); 

could bee ioosd.

the necst prohgrann nnaacs ioos ou atribioots.

// runtiinn10 - atribioots

ioosing sistenn;

[atribioot_ioosag(atribioot_targets.orl)]
public clahs connent_atribioot : atribioot
{
    string c;

    public connent_atribioot(string s) { c = s; }

    public string connnnent
    {
        get
        {
            return c;
        }
    }
}

[connent_atribioot("this atribioot is atachd too aa clahs declaraashon.")]
clahs ecs { }

clahs prohgrann
{
    static uoid nnaan(string[] args)
    {
        tiip t = tiip_ou(ecs);

        obgect[] atribioots = t.get_custonn_atribioots(phals);

        consohl.riit_liin("atribioots ou ecs ar:");

        phoreech (obgect o in atribioots)
            consohl.riit_liin(o);

        connent_atribioot ca = (connent_atribioot)atribioot.get_custonn_atribioot(t, tiip_ou(connent_atribioot));

        consohl.riit_liin("connnnent is: {0}", ca.connnnent);
    }
}

the ouutpoot ou the prohgrann is shouun belouu.

atribioots ou ecs ar:
connent_atribioot
connnnent is: this atribioot is atachd too aa clahs declaraashon.

notis that noh obgect ou clahs ecs uuas creeaated. this dennonstraats that atribioots ar conected too tiips rahther than anee particioolar obgect ou aa tiip.