国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

【轉載】#470 Define Your Own Custom Attribute

2019-11-17 03:16:36
字體:
來源:轉載
供稿:網友

【轉載】#470 Define Your Own Custom Attribute

You can use PRedefined attributes to attach metadata to type members.

You can also define a custom attribute by creating a new class inheriting from System.Attribute. The class name must end in "Attribute". You typically define a conostructor that takes arguments that consist of the metadata that you want to attach to the type membere.

 1 /// <summary> 2 /// Attach to a class method to indicate kg of methane that is 3 /// output when calling the method. 4 /// </summary> 5 public class MethaneFootprintAttribute : Attribute 6 { 7     public double kgMethane; 8   9     public MethaneFootprintAttribute(int kg)10     {11         kgMethane = kg;12     }13 }

You can use the new attribute to attach metadata to individual type members. You use the name of the new class, without the trailing "Attribute".

 1 [MethaneFootprint(45)] 2 public void FeedCowInBarn() 3 { 4     Console.WriteLine("Cow eats slop in dim confines of barn"); 5 } 6   7 [MethaneFootprint(29)] 8 public void LetGrazeOutside() 9 {10     Console.WriteLine("Cow enjoys grazing and ends up healthier");11 }

原文地址:#470 Define Your Own Custom Attribute


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清徐县| 南郑县| 筠连县| 清丰县| 绥宁县| 甘洛县| 灵丘县| 徐汇区| 康马县| 九龙坡区| 永州市| 绩溪县| 永兴县| 衡水市| 治县。| 个旧市| 舟曲县| 东乌珠穆沁旗| 蒲江县| 宝鸡市| 呼伦贝尔市| 汉中市| 娄底市| 临海市| 方正县| 柳林县| 司法| 九龙坡区| 定南县| 嘉义县| 庐江县| 堆龙德庆县| 唐海县| 蕲春县| 西贡区| 阳城县| 肥西县| 肃北| 武定县| 温州市| 新乐市|