当前位置: 首页 > news >正文

dede网站地图调用嵌入式软件开发工程师培训

dede网站地图调用,嵌入式软件开发工程师培训,做一份网站的步zou,自建站需要多少钱一直以来都没理解attribute是个什么东西#xff0c;也没怎么用#xff0c;但是看msdn或者git上源码使用的还是蛮频繁的#xff0c;今天好好整理了下#xff0c;写下自己的理解和例子#xff1a; attribute主要用来说明代码段的的信息#xff0c;标志等#xff1b;可以一…一直以来都没理解attribute是个什么东西也没怎么用但是看msdn或者git上源码使用的还是蛮频繁的今天好好整理了下写下自己的理解和例子 attribute主要用来说明代码段的的信息标志等可以一种元数据结构不会影响到代码段的结果。这个代码段可以是class,struct,method,constructor等结构下面会给出反编译源码说明哪些代码段可以作为目标。 1.NET内建attribute          [AttributeUsage] AttributeUsage主要用来限定attribute可以在哪些情况下下使用,下面是AtttributeUsage的多个构造函数中的一个其他不赘述 internal AttributeUsageAttribute(AttributeTargets validOn, bool allowMultiple, bool inherited)     {       this.m_attributeTarget validOn;       this.m_allowMultiple allowMultiple;       this.m_inherited inherited;     }    参数说明 1AttributeTarges必要的参数反编译得到attribute的目标     public enum AttributeTargets   {     [__DynamicallyInvokable] Assembly 1,     [__DynamicallyInvokable] Module 2,     [__DynamicallyInvokable] Class 4,     [__DynamicallyInvokable] Struct 8,     [__DynamicallyInvokable] Enum 16, // 0x00000010     [__DynamicallyInvokable] Constructor 32, // 0x00000020     [__DynamicallyInvokable] Method 64, // 0x00000040     [__DynamicallyInvokable] Property 128, // 0x00000080     [__DynamicallyInvokable] Field 256, // 0x00000100     [__DynamicallyInvokable] Event 512, // 0x00000200     [__DynamicallyInvokable] Interface 1024, // 0x00000400     [__DynamicallyInvokable] Parameter 2048, // 0x00000800     [__DynamicallyInvokable] Delegate 4096, // 0x00001000     [__DynamicallyInvokable] ReturnValue 8192, // 0x00002000     [__DynamicallyInvokable] GenericParameter 16384, // 0x00004000     [__DynamicallyInvokable] All GenericParameter | ReturnValue | Delegate | Parameter | Interface | Event | Field | Property | Method | Constructor | Enum | Struct | Class | Module | Assembly, // 0x00007FFF   }          2allowMutiple是bool类型可选的参数ture表示可以在同一个代码段多次使用默认的是false 3inherited是bool类型可选的参数ture表示在派生类中继承默认的值false [Obsolete] 主要用来指示代码段是废弃的并通知编译器编译器将会给出警告或者错误 用法[Obsolete(message)]  和[Obsolte(message(string),iserror(bool))] message:描述代码段废弃的原因并指出替代者iserror当它是true时编译器报错默认时false 这里放代码的话看不出来编译错误上图明显显示错误并指示应该时NewMethod。 [Conditional] 主要用来定义一个预定义符号作为编译条件类似#ifdef的作用下面例子说明用法 #define Test using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks;   namespace Experiments {     class Program     {         static void Main(string[] args)         {                          System.Console.ReadKey();             DoWork();         }           [Conditional(Test)]         static void DoWork()         {             for (int i 0; i 100; i)             {                 Console.WriteLine(i);                 Thread.Sleep(100);             }         }     } }   当没有定义#define TestDoWork方法不执行 [CallerMemberName] 可以自动展示调用者的名字用在INotifyPerprotyChanged例子 public class MyUIClass : INotifyPropertyChanged     {         public event PropertyChangedEventHandler PropertyChanged;           public void RaisePropertyChanged([CallerMemberName] string propertyName null)         {             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));         }           private string _name;         public string Name         {             get { return _name; }             set             {                 if (value ! _name)                 {                     _name value;                     RaisePropertyChanged();   // notice that Name is not needed here explicitly                 }             }         }     } 2自定义attribute      自定义的attribute必须要继承自Attribute基类其参数按照MSDN解释分为位置参数positional parameter和可选的命名参数(named parameter)。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;   namespace Experiments {     [AttributeUsage(AttributeTargets.Class                     |AttributeTargets.Constructor                     |AttributeTargets.Field                     |AttributeTargets.Method                     |AttributeTargets.Property, AllowMultiple true)]     public class DevelopLog:Attribute     {         //positional parameter         private string _developer;         private string _reviewer;         private string _lastModTime;         //named parameter         private string msg;                    public string Developer { get _developer;  }         public string Reviewer { get _reviewer; }         public string LastModTime { get _lastModTime;  }         public string Msg { get msg; set msg value; }           public DevelopLog(string dev, string rv, string lmt)         {             _developer dev;             _reviewer rv;             _lastModTime lmt;         }     } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;   namespace Experiments {          [DevelopLog(zhangsan, boss, 20180807, Msg create class)]     [DevelopLog(lisi, boss, 20180807, Msg add method dowork)]     public class Student     {         private string _name;         private string _age;           public Student(string n, string a)         {             _name n;             _age a;         }           [DevelopLog(zhangsan, boss, 20180807)]         public void EvertyDayDoThing()         {           }         [DevelopLog(zhangsan, boss, 20180807)]         public void MoringDo()         {           }         [DevelopLog(lisi, boss, 20180808)]         public void NoonDo()         {           }           [DevelopLog(zhangsan, boss, 20180807, Msgpaly game all day and not do homework)]         public void PlayGame()         {           }     } }   然后在实际应用中我们可以通过reflection来获取上面描述的attribute从而获取有价值的信息
http://www.sadfv.cn/news/9902/

相关文章:

  • 网站建设程序做哪些个人特种证件查询网站
  • 购物网站建设怎么样济南市建设银行网站
  • 建设广州公司网站wordpress装在根目录文件夹中_如何通过域名直接访问?
  • 什么网站建设德国著名的外贸公司地址
  • 怎样做团购网站没有公司地址怎么注册公司
  • 专业苏州网站建设公司哪家好免费资源源码网站
  • 英文网站注册迁西网站定制
  • 值得浏览的国外网站大连网站建设流程图
  • 网站的数据运营怎么做制作网络网站
  • 响应式网站制作wordpress js加载位置
  • 电子商务网站建设与管理期末答案上海备案证查询网站
  • 做线上网站需要钱吗食品网站建设的目的
  • 临沭有做网站的吗深圳设计公司排名深圳市广告公司
  • 网站设计优化永久免费手机网站自助建站
  • 网站功能价格表谢岗镇仿做网站
  • 网站设计的技巧织梦批量修改网站源代码
  • wordpress总是跳出淘宝排名优化公司口碑哪家好
  • 做暧暧视频网站下载广告策划案
  • 网站用什么主机网站建设 招聘需求
  • 京东网站建设的主旨贝锐免费域名
  • 微网站搭建网站怎么做301跳转
  • 网站建设初学软件网络舆情处置的五个步骤
  • 2022中文无字幕入口网站wordpress ios 默认
  • 有什么做ppt参考的网站wordpress模板转为emlog
  • 茂名一站式网站建设报价wordpress博客手机新闻模板
  • 网站建设给客户看的ppt模板如何申请一个网址
  • 网站建设需要步骤wordpress菜单显示在哪里
  • wordpress 企业站模板怎么样购买服务器建设网站
  • 网页网站设计培训班seo全称是什么意思
  • 网站seo系统门户网站app有哪些