C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet607/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   603   604   605   606   607   608   609   610   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Creating an Attribute

In an attribute class, you will define the members that support the attribute. Often attribute 

classes are quite simple, containing just a small number of fields or properties. For example, 

an attribute might define a remark that describes the item to which the attribute is being 

attached. Such an attribute might look like this:

 [AttributeUsage(AttributeTargets.All)]

public class RemarkAttribute : Attribute {

  string pri_remark; // underlies Remark property

  public RemarkAttribute(string comment) {

    pri_remark = comment;

  }

  public string Remark {



    get {

      return pri_remark;

    }

  }


}

Let’s look at this class, line by line.

The name of this attribute is 

RemarkAttribute

. Its declaration is preceded by the 



AttributeUsage

 attribute, which specifies that 



RemarkAttribute

 can be applied to all 

types of items. Using 

AttributeUsage

, it is possible to narrow the list of items to which 

an attribute can be attached, and we will examine its capabilities later in this chapter.

Next,


RemarkAttribute

 is declared and it inherits 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   603   604   605   606   607   608   609   610   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish