国产探花免费观看_亚洲丰满少妇自慰呻吟_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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 错那县| 洛隆县| 延长县| 绥棱县| 涿鹿县| 砀山县| 武宣县| 孝昌县| 工布江达县| 桐城市| 崇州市| 隆德县| 长寿区| 新巴尔虎左旗| 六枝特区| 民勤县| 新邵县| 四子王旗| 集贤县| 屏南县| 扬州市| 延安市| 厦门市| 罗甸县| 衡南县| 美姑县| 嘉善县| 金塔县| 兴仁县| 怀仁县| 万盛区| 库尔勒市| 囊谦县| 唐海县| 定州市| 乌拉特中旗| 柘荣县| 麟游县| 东乡族自治县| 章丘市| 嵊州市|