{"id":3730,"date":"2023-06-11T00:30:46","date_gmt":"2023-06-10T16:30:46","guid":{"rendered":"https:\/\/lonelinerd.com\/?p=3730"},"modified":"2023-06-11T00:44:52","modified_gmt":"2023-06-10T16:44:52","slug":"custom-attribute","status":"publish","type":"post","link":"https:\/\/lonelinerd.com\/index.php\/2023\/06\/11\/custom-attribute\/","title":{"rendered":"C#\u7b46\u8a18 \u2013 \u5b9a\u5236\u7279\u6027"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"3730\" class=\"elementor elementor-3730\">\n\t\t\t\t\t\t<div class=\"elementor-inner\">\n\t\t\t\t<div class=\"elementor-section-wrap\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-eedb374 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"eedb374\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f8bfad3\" data-id=\"f8bfad3\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-11e19ba elementor-widget elementor-widget-text-editor\" data-id=\"11e19ba\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p md-focus\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u300c\u81ea\u5b9a\u7fa9\u7279\u6027\u300d\u53ea\u662f\u5c07\u4e00\u4e9b\u9644\u52a0\u4fe1\u606f\u8207\u67d0\u500b\u76ee\u6a19\u5143\u7d20\u95dc\u806f\u8d77\u4f86\u7684\u65b9\u5f0f<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u7de8\u8b6f\u5668\u5728<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u6258\u7ba1\u6a21\u584a\u7684\u5143\u6578\u64da\u4e2d\u751f\u6210<\/span><\/span><\/span><span class=\"md-plain\">\u9019\u4e9b\u984d\u5916\u7684\u4fe1\u606f<\/span><\/p><\/li><li class=\"md-list-item md-focus-container\"><p class=\"md-end-block md-p md-focus\"><span class=\"md-plain md-expand\">\u6700\u5e38\u61c9\u7528\u7279\u6027\u7684\u8a18\u9304\u9805\uff1a<\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">TypeDef<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">MethodDef<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">ParamDef<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">FieldDef<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">PropertyDef<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">EventDef<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">AssemblyDef<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">ModuleDef<\/span><\/p><\/li><\/ul><\/li><\/ul><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u300c\u81ea\u5b9a\u7fa9\u7279\u6027\u300d\u5be6\u969b\u4e0a\u662f\u4e00\u500b<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u300c\u985e\u578b\u7684\u5be6\u4f8b\u300d\uff0c\u6d3e\u751f\u81eaSystem.Attribute<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u800c\u300c\u985e\u300d<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u5fc5\u9808\u6709\u516c\u5171\u69cb\u9020\u5668<\/span><\/span><\/span><span class=\"md-plain\">\u624d\u80fd\u5275\u5efa\u5b83\u7684\u5be6\u4f8b<\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u5c07\u7279\u6027\u61c9\u7528\u65bc\u76ee\u6a19\u5143\u7d20\u6642\uff0c\u985e\u4f3c\u65bc\u8abf\u7528\u5176\u5be6\u4f8b\u69cb\u9020\u5668<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u61c9\u7528\u7279\u6027\u6642\uff0c<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u5411\u5176\u300c\u69cb\u9020\u5668\u300d\u50b3\u905e\u7684\u53c3\u6578\u70ba\uff1a\u300c\u5b9a\u4f4d\u53c3\u6578\u300d<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u8a72\u53c3\u6578\u662f\u5f37\u5236\u6027<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u5fc5\u9808\u6307\u5b9a<\/span><\/span><\/span><span class=\"md-plain\">\u7684<\/span><\/p><\/li><\/ul><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u53e6\u5916\u4e5f\u53ef\u4ee5\u8a2d\u7f6e<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u8207\u7279\u6027\u985e\u95dc\u806f\u7684\u516c\u5171\u5b57\u6bb5\/\u5c6c\u6027<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u7528\u65bc\u8a2d\u7f6e\u9019\u4e9b\u5b57\u6bb5\/\u5c6c\u6027\u7684\u53c3\u6578\u70ba\uff1a<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u300c\u547d\u540d\u53c3\u6578\u300d<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u4e0d\u4e00\u5b9a\u8981\u6307\u5b9a<\/span><\/p><\/li><\/ul><\/li><\/ul><\/li><li class=\"md-list-item\"><pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"C#\" spellcheck=\"false\"><span role=\"presentation\">[<span class=\"cm-variable\">DllImport<\/span>(<span class=\"cm-string\">\"TestDLL\"<\/span>, <span class=\"cm-variable\">CharSet<\/span> <span class=\"cm-operator\">=<\/span> <span class=\"cm-variable\">CharSet<\/span>.<span class=\"cm-variable\">Auto<\/span>, <span class=\"cm-variable\">SetLastError<\/span> <span class=\"cm-operator\">=<\/span> <span class=\"cm-atom\">true<\/span>)]<\/span><br \/><span role=\"presentation\"><span class=\"cm-keyword\">public<\/span> <span class=\"cm-keyword\">static<\/span> <span class=\"cm-keyword\">extern<\/span> <span class=\"cm-keyword\">void<\/span> <span class=\"cm-variable\">TestMethod<\/span>(); \u00a0 \u00a0 \u00a0<\/span><\/pre><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">&#8220;TestDLL&#8221; \u70ba\u300c\u5b9a\u4f4d\u53c3\u6578\u300d\uff1bCharSet = CharSet.Auto\u548cSetLastError = true\u70ba\u300c\u547d\u540d\u53c3\u6578\u300d<\/span><\/p><\/li><\/ul><\/li><\/ul><\/li><\/ul><h5 class=\"md-end-block md-heading\"><strong><span class=\"md-plain\">\u81ea\u5b9a\u7fa9\u7279\u6027\u985e<\/span><\/strong><\/h5><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u7279\u6027\u985e\u5fc5\u9808\u7e7c\u627f\u81eaAttribute<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"C#\" spellcheck=\"false\"><span role=\"presentation\"><span class=\"cm-keyword\">public<\/span> <span class=\"cm-keyword\">class<\/span> <span class=\"cm-def\">MyAttribute<\/span> : <span class=\"cm-variable\">Attribute<\/span>{}<\/span><\/pre><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u61c9\u628a\u7279\u6027\u985e\u60f3\u6210\u4e00\u500b<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u300c\u908f\u8f2f\u72c0\u614b\u5bb9\u5668\u300d<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u985e\u7684\u5167\u5bb9\u5f88\u7c21\u55ae<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u61c9\u53ea\u63d0\u4f9b\u4e00\u500b\u516c\u5171\u69cb\u9020\u5668\u4f86\u63a5\u53d7\u7279\u6027\u7684\u300c\u5b9a\u4f4d\u53c3\u6578\u300d<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u53ef\u4ee5\u63d0\u4f9b\u516c\u5171\u5b57\u6bb5\u548c\u5c6c\u6027\u4f86\u63a5\u53d7\u300c\u547d\u540d\u53c3\u6578\u300d<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u4e0d\u61c9\u63d0\u4f9b\u4efb\u4f55\u516c\u5171\u65b9\u6cd5\u3001\u4e8b\u4ef6\u7b49\u5176\u4ed6\u6210\u54e1<\/span><\/span><\/span><\/p><\/li><\/ul><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u5982\u679c\u8981\u8b93\u4e00\u500b\u7279\u6027\u5411\u7de8\u8b6f\u5668<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u6307\u5b9a\u5b83\u7684\u5408\u6cd5\u61c9\u7528\u7bc4\u570d<\/span><\/span><\/span><span class=\"md-plain\">\uff0c\u9700\u8981\u5411\u7279\u6027\u985e\u61c9\u7528<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">System.AttributeUsageAttribute\u7279\u6027<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u7531\u65bc\u7279\u6027\u672c\u8cea\u4e0a\u662f\u4e00\u500b\u985e\u7684\u5be6\u4f8b\uff0c\u56e0\u6b64\uff0c\u5176\u4f5c\u70ba\u4e00\u500b\u985e\u672c\u8eab\u4e5f\u53ef\u4ee5\u61c9\u7528\u5176\u4ed6\u7279\u6027<\/span><\/p><\/li><li class=\"md-list-item\"><pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"C#\" spellcheck=\"false\"><span role=\"presentation\">[<span class=\"cm-variable\">AttributeUsage<\/span>(<span class=\"cm-variable\">AttributeTargets<\/span>.<span class=\"cm-variable\">Enum<\/span>, <span class=\"cm-variable\">Inherited<\/span> <span class=\"cm-operator\">=<\/span> <span class=\"cm-atom\">false<\/span>)]<\/span><br \/><span role=\"presentation\"><span class=\"cm-keyword\">public<\/span> <span class=\"cm-keyword\">class<\/span> <span class=\"cm-def\">MyAttribute<\/span> : <span class=\"cm-variable\">Attribute<\/span>{}<\/span><\/pre><\/li><\/ul><\/li><\/ul><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u7279\u6027\u69cb\u9020\u5668\u53ef\u63a5\u53d7\u7684\u5b57\u6bb5\/\u5c6c\u6027\u6578\u64da\u985e\u578b\u90fd\u662f\u4e00\u4e9b\u7c21\u55ae\u7684\u6578\u64da\u985e\u578b\uff0c\u5982<\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">bool\/char\/byte\/sbyte\/int\/uint\/single\/double\/string\/type\/object\/enum<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u53ef\u4f7f\u7528\u4e0a\u8ff0\u985e\u578b\u7684SZ\u6578\u7d44\uff0c\u4f46\u61c9\u76e1\u91cf\u907f\u514d\u4f7f\u7528\u3002<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u5982\u679c\u7372\u53d6\u6578\u7d44\u4f5c\u70ba\u53c3\u6578\uff0c\u5c07\u6703\u5931\u53bb\u8207CLS\u7684\u76f8\u5bb9\u6027<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u61c9\u7528\u7279\u6027\u6642\u5fc5\u9808\u50b3\u905e\u4e00\u500b\u7de8\u8b6f\u6642\u7684\u5e38\u91cf\u8868\u9054\u5f0f\uff0c\u5b83\u8207\u7279\u6027\u985e\u5b9a\u7fa9\u7684\u985e\u578b\u5339\u914d<\/span><\/p><\/li><\/ul><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u7576\u7de8\u8b6f\u5668\u6aa2\u6e2c\u5230\u5411\u76ee\u6a19\u5143\u7d20\u61c9\u7528\u4e86\u5b9a\u5236\u7279\u6027\u5f8c\uff0c\u6703\u8abf\u7528\u7279\u6027\u7684\u985e\u69cb\u9020\u5668\uff0c\u5411\u5b83\u50b3\u905e\u4efb\u4f55\u6307\u5b9a\u7684\u53c3\u6578\uff0c\u5f9e\u800c\u69cb\u9020\u7279\u6027\u985e\u7684\u5be6\u4f8b<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u7136\u5f8c\uff0c\u7de8\u8b6f\u5668\u63a1\u7528\u589e\u5f37\u578b\u69cb\u9020\u5668\u8a9e\u6cd5\u6240\u6307\u5b9a\u7684\u503c\uff0c\u5c0d\u4efb\u4f55\u516c\u5171\u5b57\u6bb5\/\u5c6c\u6027\u9032\u884c\u521d\u59cb\u5316<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u6700\u5f8c\uff0c\u7de8\u8b6f\u5668\u5c07\u5176\u72c0\u614b\u5e8f\u5217\u5316\u5230\u76ee\u6a19\u5143\u7d20\u7684\u5143\u6578\u64da\u8868\u8a18\u9304\u9805\u4e2d<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"C#\" spellcheck=\"false\"><span role=\"presentation\">[<span class=\"cm-variable\">MyAttribute<\/span>]<\/span><br \/><span role=\"presentation\"><span class=\"cm-keyword\">public<\/span> <span class=\"cm-keyword\">enum<\/span> <span class=\"cm-variable\">TestAttribute<\/span><\/span><br \/><span role=\"presentation\">{<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-variable\">None<\/span><\/span><br \/><span role=\"presentation\">}<\/span><br \/><span role=\"presentation\">\u200b<\/span><br \/><span role=\"presentation\">[<span class=\"cm-variable\">AttributeUsage<\/span>(<span class=\"cm-variable\">AttributeTargets<\/span>.<span class=\"cm-variable\">Enum<\/span>)]<\/span><br \/><span role=\"presentation\"><span class=\"cm-keyword\">public<\/span> <span class=\"cm-keyword\">class<\/span> <span class=\"cm-def\">MyAttribute<\/span> : <span class=\"cm-variable\">Attribute<\/span><\/span><br \/><span role=\"presentation\">{<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-keyword\">public<\/span> <span class=\"cm-variable\">MyAttribute<\/span>(){}<\/span><br \/><span role=\"presentation\">}<\/span><\/pre><\/li><li class=\"md-list-item\"><pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"\" spellcheck=\"false\"><span role=\"presentation\">TypeDef #1 (02000002)<\/span><br \/><span role=\"presentation\">-------------------------------------------------------<\/span><br \/><span role=\"presentation\">TypDefName: CLR_Ch18.TestAttribute  (02000002)<\/span><br \/><span role=\"presentation\">Flags \u00a0 \u00a0 : [Public] [AutoLayout] [Class] [Sealed] [AnsiClass]  (00000101)<\/span><br \/><span role=\"presentation\">Extends \u00a0 : 0100000C [TypeRef] System.Enum<\/span><br \/><span role=\"presentation\">Field #1 (04000001)<\/span><br \/><span role=\"presentation\">-------------------------------------------------------<\/span><br \/><span role=\"presentation\">Field Name: value__ (04000001)<\/span><br \/><span role=\"presentation\">Flags \u00a0 \u00a0 : [Public] [SpecialName] [RTSpecialName]  (00000606)<\/span><br \/><span role=\"presentation\">CallCnvntn: [FIELD]<\/span><br \/><span role=\"presentation\">Field type:  I4<\/span><br \/><span role=\"presentation\">\u200b<\/span><br \/><span role=\"presentation\">Field #2 (04000002)<\/span><br \/><span role=\"presentation\">-------------------------------------------------------<\/span><br \/><span role=\"presentation\">Field Name: None (04000002)<\/span><br \/><span role=\"presentation\">Flags \u00a0 \u00a0 : [Public] [Static] [Literal] [HasDefault]  (00008056)<\/span><br \/><span role=\"presentation\">DefltValue: (I4) 0<\/span><br \/><span role=\"presentation\">CallCnvntn: [FIELD]<\/span><br \/><span role=\"presentation\">Field type:  ValueClass CLR_Ch18.TestAttribute<\/span><br \/><span role=\"presentation\">\u200b<\/span><br \/><span role=\"presentation\">CustomAttribute #1 (0c00000b)<\/span><br \/><span role=\"presentation\">-------------------------------------------------------<\/span><br \/><span role=\"presentation\">CustomAttribute Type: 06000004<\/span><br \/><span role=\"presentation\">CustomAttributeName: CLR_Ch18.MyAttribute :: instance void .ctor()<\/span><br \/><span role=\"presentation\">Length: 4<\/span><br \/><span role=\"presentation\">Value : 01 00 00 00 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  &gt; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  &lt;<\/span><br \/><span role=\"presentation\">ctor args: ()<\/span><\/pre><\/li><\/ul><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u7406\u89e3\u5b9a\u5236\u7279\u6027<\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u5b83\u662f\u985e\u7684\u5be6\u4f8b\uff0c\u88ab\u5e8f\u5217\u5316\u6210\u99d0\u7559\u5728\u6578\u64da\u4e2d\u7684\u5b57\u7bc0\u6d41<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u904b\u884c\u6642\u53ef\u5c0d\u5143\u6578\u64da\u4e2d\u7684\u5b57\u7bc0\u9032\u884c\u53cd\u5e8f\u5217\u5316\uff0c\u69cb\u9020\u51fa\u7279\u6027\u985e\u7684\u5be6\u4f8b<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u5be6\u969b\u767c\u751f\uff1a<\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u7de8\u8b6f\u5668\u5728\u5143\u6578\u64da\u4e2d\u751f\u6210\u5275\u5efa\u7279\u6027\u985e\u7684\u5be6\u4f8b\u6240\u9700\u7684\u4fe1\u606f<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u6bcf\u500b\u69cb\u9020\u5668\u53c3\u6578\u90fd\u662f1\u5b57\u7bc0\u7684\u985e\u578bID\uff0c\u5f8c\u8ddf\u5177\u9ad4\u7684\u503c<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u5c0d\u69cb\u9020\u5668\u9032\u884c\u300c\u5e8f\u5217\u5316\u300d\u6642\uff0c\u7de8\u8b6f\u5668\u5148\u5beb\u5165\u5b57\u6bb5\/\u5c6c\u6027\u540d\uff0c\u518d\u8ddf\u4e0a1\u5b57\u7bc0\u7684\u985e\u578bID\uff0c\u6700\u5f8c\u662f\u5177\u9ad4\u7684\u503c<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u5982\u679c\u662f\u6578\u7d44\uff0c\u5247\u6703\u5148\u4fdd\u5b58\u6578\u7d44\u5143\u7d20\u7684\u500b\u6578\uff0c\u518d\u8ddf\u4e0a\u6bcf\u500b\u55ae\u7368\u7684\u5143\u7d20<\/span><\/span><\/span><\/p><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ca1432b elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ca1432b\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-747b4f5\" data-id=\"747b4f5\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9a9c57b elementor-widget elementor-widget-text-editor\" data-id=\"9a9c57b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<h5 class=\"md-end-block md-heading\"><strong><span class=\"md-plain\">\u81ea\u5b9a\u7fa9\u7279\u6027\u7684\u6aa2\u6e2c<\/span><\/strong><\/h5><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u901a\u904e<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u300c\u53cd\u5c04\u300d<\/span><\/span><\/span><span class=\"md-plain\">\u4f86\u6aa2\u6e2c<\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">IsDefined<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"C#\" spellcheck=\"false\"><span role=\"presentation\">[<span class=\"cm-variable\">MyAttribute<\/span>]<\/span><br \/><span role=\"presentation\"><span class=\"cm-keyword\">public<\/span> <span class=\"cm-keyword\">enum<\/span> <span class=\"cm-variable\">TestAttribute<\/span><\/span><br \/><span role=\"presentation\">{<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-variable\">None<\/span><\/span><br \/><span role=\"presentation\">}<\/span><br \/><span role=\"presentation\">\u200b<\/span><br \/><span role=\"presentation\"><span class=\"cm-keyword\">class<\/span> <span class=\"cm-def\">Program<\/span><\/span><br \/><span role=\"presentation\">{<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-keyword\">static<\/span> <span class=\"cm-variable\">TestAttribute<\/span> <span class=\"cm-variable\">attr<\/span> <span class=\"cm-operator\">=<\/span> <span class=\"cm-variable\">TestAttribute<\/span>.<span class=\"cm-variable\">None<\/span>; <\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-keyword\">public<\/span> <span class=\"cm-keyword\">static<\/span> <span class=\"cm-keyword\">void<\/span> <span class=\"cm-variable\">TestMethod_A<\/span>()<\/span><br \/><span role=\"presentation\"> \u00a0  {<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0 \u00a0 \u00a0<span class=\"cm-keyword\">if<\/span>(<span class=\"cm-variable\">attr<\/span>.<span class=\"cm-variable\">GetType<\/span>().<span class=\"cm-variable\">IsDefined<\/span>(<span class=\"cm-keyword\">typeof<\/span>(<span class=\"cm-variable\">MyAttribute<\/span>), <span class=\"cm-atom\">false<\/span>))<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0 \u00a0  {<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<span class=\"cm-variable\">Console<\/span>.<span class=\"cm-variable\">WriteLine<\/span>(<span class=\"cm-string\">\"Is MyAttribute\"<\/span>);<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0 \u00a0  }<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0 \u00a0 \u00a0<span class=\"cm-keyword\">else<\/span><\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0 \u00a0  {<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<span class=\"cm-variable\">Console<\/span>.<span class=\"cm-variable\">WriteLine<\/span>(<span class=\"cm-string\">\"Not MyAttribute\"<\/span>);<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0 \u00a0  }<\/span><br \/><span role=\"presentation\"> \u00a0  }<\/span><br \/><span role=\"presentation\">} \u00a0 \u00a0 \u00a0 \u00a0<\/span><br \/><span role=\"presentation\">\u200b<\/span><br \/><span role=\"presentation\">[<span class=\"cm-variable\">AttributeUsage<\/span>(<span class=\"cm-variable\">AttributeTargets<\/span>.<span class=\"cm-variable\">Enum<\/span>)]<\/span><br \/><span role=\"presentation\"><span class=\"cm-keyword\">public<\/span> <span class=\"cm-keyword\">class<\/span> <span class=\"cm-def\">MyAttribute<\/span> : <span class=\"cm-variable\">Attribute<\/span><\/span><br \/><span role=\"presentation\">{<\/span><br \/><span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-keyword\">public<\/span> <span class=\"cm-variable\">MyAttribute<\/span>(){}<\/span><br \/><span role=\"presentation\">}<\/span><\/pre><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">IsDefined\u8981\u6c42\u7cfb\u7d71\u67e5\u770b\u679a\u8209\u985e\u578b\u7684\u5143\u6578\u64da\uff0c\u6aa2\u67e5\u662f\u5426\u95dc\u806f\u4e86\u5c0d\u8c61\u7279\u6027\u985e\u7684\u5be6\u4f8b<\/span><\/span><\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u53ea\u5224\u65b7\u76ee\u6a19\u662f\u5426\u61c9\u7528\u4e86\u4e00\u500b\u7279\u6027\uff0c\u4f7f\u7528\u6642\uff0c<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u4e0d\u6703\u8abf\u7528\u7279\u6027\u5c0d\u8c61\u7684\u69cb\u9020\u5668\u6216\u8a2d\u7f6e\u5176\u5305\u542b\u7684\u5b57\u6bb5\/\u5c6c\u6027<\/span><\/span><\/span><\/p><\/li><\/ul><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">GetCustomAttribute(s)<\/span><\/span><\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u6703\u69cb\u9020\u6307\u5b9a\u7279\u6027\u985e\u578b\u7684\u65b0\u5be6\u4f8b\uff0c\u5176\u8fd4\u56de\u5c0d\u8a72\u7279\u6027\u5be6\u4f8b\u7684\u5f15\u7528<\/span><\/span><\/span><\/p><\/li><\/ul><\/li><\/ul><\/li><li class=\"md-list-item md-focus-container\"><p class=\"md-end-block md-p md-focus\"><span class=\"md-plain\">\u7121\u8ad6\u662f\u8abf\u7528\u4ee5\u4e0a\u54ea\u500b\u65b9\u6cd5\uff0c<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u5167\u90e8\u90fd\u9808\u6383\u63cf\u6258\u7ba1\u6a21\u584a\u7684\u5143\u6578\u64da\uff0c\u57f7\u884c\u5b57\u7b26\u4e32\u6bd4\u8f03\u4f86\u5b9a\u4f4d\u6307\u5b9a\u7684\u5b9a\u5236\u7279\u6027\u985e<\/span><\/span><\/span><\/p><\/li><\/ul>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-5a9a63d elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"5a9a63d\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-5a39c13\" data-id=\"5a39c13\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f06bf3a elementor-widget elementor-widget-text-editor\" data-id=\"f06bf3a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<h5 class=\"md-end-block md-heading md-focus\"><strong><span class=\"md-plain\">\u5339\u914d\u7279\u6027\u5be6\u4f8b<\/span><\/strong><\/h5><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">System.Attribute\u96d6\u7136\u91cd\u5beb\u4e86Object\u7684Equals\u65b9\u6cd5\uff0c\u4f46\u662f\u6bd4\u8f03\u4f4e\u6548<\/span><\/p><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u9996\u5148\u6703\u5728\u5167\u90e8\u6bd4\u8f03\u5169\u500b\u5c0d\u8c61\u7684\u985e\u578b<\/span><\/p><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">\u7136\u5f8c\u6703\u4f7f\u7528\u53cd\u5c04\u6bd4\u8f03\u5169\u500b\u7279\u6027\u5c0d\u8c61\u4e2d\u6bcf\u500b\u5b57\u6bb5\u7684\u503c<\/span><\/p><\/li><\/ul><\/li><li class=\"md-list-item\"><p class=\"md-end-block md-p\"><span class=\"md-plain\">System.Attribute\u9084\u516c\u958b\u4e86<\/span><span class=\"md-html-inline\" spellcheck=\"false\"><span style=\"color: red;\"><span class=\"md-plain\">\u865b\u65b9\u6cd5Match<\/span><\/span><\/span><span class=\"md-plain\">\u8b93\u6211\u5011\u91cd\u5beb<\/span><\/p><\/li><\/ul>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-15fe2de elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"15fe2de\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-31589ba\" data-id=\"31589ba\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-66cb006 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"66cb006\" data-element_type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-5ac14f0 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"5ac14f0\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-51b630d\" data-id=\"51b630d\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c69eae8 elementor-widget elementor-widget-text-editor\" data-id=\"c69eae8\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<h4 class=\"md-end-block md-heading\"><span style=\"text-decoration: underline;\"><strong><span class=\"md-plain md-expand\">\u53c3\u8003\u66f8\u76ee<\/span><\/strong><\/span><\/h4><ul class=\"ul-list\" data-mark=\"-\"><li class=\"md-list-item md-focus-container\">\u300aCLR via C#\u300b\uff08\u7b2c4\u7248\uff09 Jeffrey Richter<\/li><\/ul>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>\u300c\u81ea\u5b9a\u7fa9\u7279\u6027\u300d\u53ea\u662f\u5c07\u4e00\u4e9b\u9644\u52a0\u4fe1\u606f\u8207\u67d0\u500b\u76ee\u6a19\u5143\u7d20\u95dc\u806f\u8d77\u4f86\u7684\u65b9\u5f0f\uff0c\u7de8\u8b6f\u5668\u5728\u6258\u7ba1\u6a21\u584a\u7684\u5143\u6578\u64da\u4e2d\u751f\u6210\u9019\u4e9b\u984d\u5916\u7684\u4fe1\u606f\u3002\u300c\u81ea\u5b9a\u7fa9\u7279\u6027\u300d\u5be6\u969b\u4e0a\u662f\u4e00\u500b\u300c\u985e\u578b\u7684\u5be6\u4f8b\u300d\uff0c\u6d3e\u751f\u81eaSystem.Attribute\uff0c\u5c07\u7279\u6027\u61c9\u7528\u65bc\u76ee\u6a19\u5143\u7d20\u6642\uff0c\u985e\u4f3c\u65bc\u8abf\u7528\u5176\u5be6\u4f8b\u69cb\u9020\u5668<\/p>\n","protected":false},"author":1,"featured_media":947,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,27,18],"tags":[],"class_list":["post-3730","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-reading-notes","category-c-sharp","category-developing"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/lonelinerd.com\/wp-content\/uploads\/2021\/03\/FeatureCover_ReadingNotes.png","_links":{"self":[{"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/posts\/3730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/comments?post=3730"}],"version-history":[{"count":8,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/posts\/3730\/revisions"}],"predecessor-version":[{"id":3738,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/posts\/3730\/revisions\/3738"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/media\/947"}],"wp:attachment":[{"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/media?parent=3730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/categories?post=3730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/tags?post=3730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}