zoukankan      html  css  js  c++  java
  • C# Attribute-特性

    Type t = typeof(TestAttribute);
    
                object[] attributes = t.GetCustomAttributes(false);
    
                foreach (var attr in attributes)
                {
                    if (attr.GetType() == typeof(LogInfoAttribute))
                    {
                        LogInfoAttribute att = (LogInfoAttribute)attr;
                        Console.WriteLine(String.Format("LogInfoType:{0},,OperatorName:{1},,OperatorDateTime:{2},,Mark:{3}", att.LogInfoType, att.OperatorName, att.OperatorDateTime, att.Mark));
                    }
                }
    
                Console.WriteLine("=================================");
    
                MemberInfo[] members = t.GetMethods();
                foreach (var member in members)
                {
                    if (member.IsDefined(typeof(LogInfoAttribute), false))
                    {
                        Console.WriteLine(member.Name + "Attribute start..................");
                        object[] attrs = member.GetCustomAttributes(false);
                        foreach (var attr in attrs)
                        {
                            if (attr.GetType() == typeof(LogInfoAttribute))
                            {
                                LogInfoAttribute att = (LogInfoAttribute)attr;
                                Console.WriteLine(String.Format("LogInfoType:{0},,OperatorName:{1},,OperatorDateTime:{2},,Mark:{3}", att.LogInfoType, att.OperatorName, att.OperatorDateTime, att.Mark));
                            }
                        }
                        Console.WriteLine(member.Name + "Attribute end..................");
                    }
                }
  • 相关阅读:
    des加密
    http请求报错
    js生成二维码(jquery自带)
    tomcat跨域请求
    jsp读取properties文件
    spring+mybatis整合读取不了配置文件
    svn提交报e200007错误
    firefox兼容性问题
    Oracle学习笔记(2)
    Spring设置定时器:quartz
  • 原文地址:https://www.cnblogs.com/liuwentian/p/3213716.html
Copyright © 2011-2022 走看看