惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
S
SegmentFault 最新的问题
V
Visual Studio Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
美团技术团队
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
有赞技术团队
有赞技术团队
量子位
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
博客园 - 叶小钗
月光博客
月光博客
P
Proofpoint News Feed
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
Stack Overflow Blog
Stack Overflow Blog

博客园 - gxc

C#2.0中的泛型约束(转载) 解决‘“System.Configuration.ConfigurationSettings.AppSettings”已过时’的警告 《雷神之锤III》里求平方根倒数的函数 回溯法(vc)百鸡百钱问题 回溯法(vc)八皇后问题 六十六条经典禅语 prototype.js和Ajax 悖论 标签的使用(1) 自底向上的归并排序 自顶向下的归并排序 归并排序之归并算法 Josephus问题(循环链表) 找质数算法(Sieve of Eratosthenes筛法) 堆排序 直接选择排序 快速排序算法 Some of the new features from ASP.NET 2.0 在ASP.NET中使用AJAX
标签的使用(2)
gxc · 2006-03-29 · via 博客园 - gxc

using System;
using System.Reflection;

namespace CustomAttrCS
{
    
public enum Animal{Dog = 1,Cat,Bird,Pig}

    [AttributeUsage(AttributeTargets.Class,Inherited
=false,AllowMultiple=true)]
    
public class AnimalTypeAttribute : Attribute
    
{
        
protected Animal thePet;
        
public Animal Pet
        
{
            
get return thePet; }
            
set { thePet = Pet; }
        }


        
public AnimalTypeAttribute(Animal pet)
        
{
            thePet 
= pet;
        }

    }


    [AnimalType(Animal.Pig)]
    [AnimalType(Animal.Dog)]
    
class AnimalTypeTestClass
    
{
    }


    
class DemoClass
    
{
        
static void Main(string[] args)
        
{
            AnimalTypeTestClass testClass 
= new AnimalTypeTestClass();
            Type type 
= testClass.GetType();
            
//获取type所拥有的标签.type.GetCustomAttributes(typeof(AnimalTypeAttribute)
            AnimalTypeAttribute[] attr = (AnimalTypeAttribute[])type.GetCustomAttributes(typeof(AnimalTypeAttribute), false);

            
for (int i = 0; i < attr.Length; i++)
            
{
                Console.WriteLine(attr[i].Pet);
            }


            Console.Read();
        }

    }

}