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

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
爱范儿
爱范儿
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
S
SegmentFault 最新的问题
博客园 - Franky
博客园_首页
T
Tailwind CSS 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();
        }

    }

}