• 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..................");
                    }
                }
  • 相关阅读:
    面向对象设计原则之接口隔离原则
    面向对象设计原则之开闭原则
    [OOD]违反里氏替换原则的解决方案
    错误程序
    error: ‘for’ loop initial declarations are only allowed in C99 mode
    函数模板
    查找
    队列类模板
    栈类模板
    单链表的结点类模板
  • 原文地址:https://www.cnblogs.com/liuwentian/p/3213716.html
Copyright © 2020-2023  润新知