zoukankan      html  css  js  c++  java
  • dotnet 特性 DynamicallyInvokable 是用来做什么的

    我在 Linq 很多函数都看到 __DynamicallyInvokable 这个特性,这是一个没有官方文档的特性,也许是用来优化反射

    堆栈 网找到了以下描述

    这个 __DynamicallyInvokable 特性是没有官方文档的,好像是在 .NET Framework 4.5 的一个优化添加的特性,这个特性看起来是在优化反射缓存的值,可以让随后的反射代码运行更快。从源代码里面的 System.Reflection.Assembly.cs 文件可以看到以下描述

     // 每个神奇的(blessed)的 API 都会添加 "__DynamicallyInvokableAttribute" 注释
     // Each blessed API will be annotated with a "__DynamicallyInvokableAttribute".
     // 这个 "__DynamicallyInvokableAttribute" 特性类是在他自己的程序集定义
     // This "__DynamicallyInvokableAttribute" is a type defined in its own assembly.
     // 所以他的构造函数总是一个 MethodDef 同时是 TypeDef 类型
     // So the ctor is always a MethodDef and the type a TypeDef.
     // 我们缓存此构造的 MethodDef 标记以便更快地进行自定义属性查找
     // We cache this ctor MethodDef token for faster custom attribute lookup.
     // 如果在程序集里面不包含这个特性,那么意味着这个程序集不存在任何神奇的(blessed)的 API 方法
     // If this attribute type doesn't exist in the assembly, it means the assembly
     // doesn't contain any blessed APIs.
     Type invocableAttribute = GetType("__DynamicallyInvokableAttribute", false);
     if (invocableAttribute != null)
     {
         Contract.Assert(((MetadataToken)invocableAttribute.MetadataToken).IsTypeDef);
    
         ConstructorInfo ctor = invocableAttribute.GetConstructor(Type.EmptyTypes);
         Contract.Assert(ctor != null);
    
         int token = ctor.MetadataToken;
         Contract.Assert(((MetadataToken)token).IsMethodDef);
    
         flags |= (ASSEMBLY_FLAGS)token & ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_TOKEN_MASK;
     }
    

    源代码请看 Assembly.cs

    我搭建了自己的博客 https://blog.lindexi.com/ 欢迎大家访问,里面有很多新的博客。只有在我看到博客写成熟之后才会放在csdn或博客园,但是一旦发布了就不再更新

    如果在博客看到有任何不懂的,欢迎交流,我搭建了 dotnet 职业技术学院 欢迎大家加入

    知识共享许可协议
    本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接:http://blog.csdn.net/lindexi_gd ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系

  • 相关阅读:
    Java -- JDBC 批处理
    Java -- JDBC mysql读写大数据,文本 和 二进制文件
    Python之操作符优先级
    闲聊之Python的数据类型
    UPX和WinUpack压缩壳的使用和脱法
    改进我们的小游戏
    Python while循环语法
    Python条件分支语法
    python条件分支
    小插曲之变量和字符串
  • 原文地址:https://www.cnblogs.com/lindexi/p/12086752.html
Copyright © 2011-2022 走看看