C#编译器对于dynamic对象到底做了什么
private static void TestMethod()
{
//dynamic 仅仅是个占位符而已
dynamic p1 = new { X = , Y = };
//对dynamic对象p1的X属性访问通过CallSite来实现,并且CallSite可以Cache
object p1x = p1.X;
object p1y = p1.Y; //dynamic 仅仅是个占位符而已
dynamic p2 = new { X = , Y = , Z = };
object p2x = p2.X;
object p2y = p2.Y;
object p2z = p2.Z; }
对于如上所示的含有dynamic调用的C#方法编译后大致的结果如下:
using System;
using Microsoft.CSharp.RuntimeBinder;
using System.Runtime.CompilerServices; private static void TestMethod()
{
object p1 = new {
X = ,
Y = 0x59
}; if (TestMethod_SiteContainer.p_Sitea == null)
{
TestMethod_SiteContainer.p_Sitea = CallSite<Func<CallSite, object, object>>.Create(Binder.GetMember(CSharpBinderFlags.None, "X", typeof(Program), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }));
}
object p1x = TestMethod_SiteContainer.p_Sitea.Target(TestMethod_SiteContainer.p_Sitea, p1); if (TestMethod_SiteContainer.p_Siteb == null)
{
TestMethod_SiteContainer.p_Siteb = CallSite<Func<CallSite, object, object>>.Create(Binder.GetMember(CSharpBinderFlags.None, "Y", typeof(Program), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }));
}
object p1y = TestMethod_SiteContainer.p_Siteb.Target(TestMethod_SiteContainer.p_Siteb, p1); object p2 = new {
X = ,
Y = 0x59,
Z =
}; if (TestMethod_SiteContainer.p_Sitec == null)
{
TestMethod_SiteContainer.p_Sitec = CallSite<Func<CallSite, object, object>>.Create(Binder.GetMember(CSharpBinderFlags.None, "X", typeof(Program), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }));
}
object p2x = TestMethod_SiteContainer.p_Sitec.Target(TestMethod_SiteContainer.p_Sitec, p2); if (TestMethod_SiteContainer.p_Sited == null)
{
TestMethod_SiteContainer.p_Sited = CallSite<Func<CallSite, object, object>>.Create(Binder.GetMember(CSharpBinderFlags.None, "Y", typeof(Program), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }));
}
object p2y = TestMethod_SiteContainer.p_Sited.Target(TestMethod_SiteContainer.p_Sited, p2); if (TestMethod_SiteContainer.p_Sitee == null)
{
TestMethod_SiteContainer.p_Sitee = CallSite<Func<CallSite, object, object>>.Create(Binder.GetMember(CSharpBinderFlags.None, "Z", typeof(Program), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }));
}
object p2z = TestMethod_SiteContainer.p_Sitee.Target(TestMethod_SiteContainer.p_Sitee, p2);
} [CompilerGenerated]
private static class TestMethod_SiteContainer
{
// Fields
public static CallSite<Func<CallSite, object, object>> p_Sitea;
public static CallSite<Func<CallSite, object, object>> p_Siteb;
public static CallSite<Func<CallSite, object, object>> p_Sitec;
public static CallSite<Func<CallSite, object, object>> p_Sited;
public static CallSite<Func<CallSite, object, object>> p_Sitee;
}
C#编译器对于dynamic对象到底做了什么的更多相关文章
- AFNetworking到底做了什么
写在开头: 作为一个iOS开发,也许你不知道NSUrlRequest.不知道NSUrlConnection.也不知道NSURLSession...(说不下去了...怎么会什么都不知道...)但是你一定 ...
- volatile关键字到底做了什么?
话不多说,直接贴代码 class Singleton { private static volatile Singleton instance; private Singleton(){} //双重判 ...
- AFNetworking到底做了什么?(二)
接着上一篇的内容往下讲,如果没看过上一篇内容可以点这: AFNetworking到底做了什么? 之前我们讲到NSUrlSession代理这一块: 代理8: /* task完成之后的回调,成功和失败 ...
- 一个Java对象到底占用多大内存?
最近在读<深入理解Java虚拟机>,对Java对象的内存布局有了进一步的认识,于是脑子里自然而然就有一个很普通的问题,就是一个Java对象到底占用多大内存? 在网上搜到了一篇博客讲的非常好 ...
- 一个Java对象到底占用多大内存
在网上搜到了一篇博客讲的非常好,里面提供的这个类也非常实用: import java.lang.instrument.Instrumentation; import java.lang.reflect ...
- 一个Java对象到底占多大内存
最近在读<深入理解Java虚拟机>,对Java对象的内存布局有了进一步的认识,于是脑子里自然而然就有一个很普通的问题,就是一个Java对象到底占用多大内存? 在网上搜到了一篇博客讲的非常好 ...
- new到底做了什么?
下面是一个实例化自定义的对象,我们将要对他进行分析 //定义构造函数 function A(){ this.b = 1 //在这个对象里增加一个属性 //不可以拥有返回对象的return语句 } va ...
- 一个Java对象到底占多大内存?(转)
最近在读<深入理解Java虚拟机>,对Java对象的内存布局有了进一步的认识,于是脑子里自然而然就有一个很普通的问题,就是一个Java对象到底占用多大内存? 在网上搜到了一篇博客讲的非常好 ...
- MySQL实战 | 01-当执行一条 select 语句时,MySQL 到底做了啥?
原文链接:当执行一条 select 语句时,MySQL 到底做了啥? 也许,你也跟我一样,在遇到数据库问题时,总时茫然失措,想重启解决问题,又怕导致数据丢失,更怕重启失败,影响业务. 就算重启成功了, ...
随机推荐
- pcap支持Python2.7.8解决办法
pcap库只支持到python2.5. pip install pcap在python2.7.8找不到. 只需要将网盘的2个文件放到python安装目录下lib/site-package文件夹即可 链 ...
- Topself
TopShelf简介 个人理解:开源.跨平台的服务框架.提供一种方式以控制台编写windows服务,与windows服务相比,目前只发现便于调试. 官网网站:http://docs.topshelf- ...
- Fetch的使用
import React,{ Component } from 'react'; import { AppRegistry, ListView, Image, Text, StyleSheet, Vi ...
- JBPM WEB CONSOLE安装实录
http://www.blogjava.net/paulwong/archive/2009/03/13/259551.html JBPM WEB CONSOLE是一个B/S端的,能管理JBPM的流程和 ...
- ASP.NET MVC(二) 理解MVC
MVC模型同时提供对HTML.CSS以及JavaScript的完整控制. MVC模型通过三个逻辑层来定义WEB应用程序: (一)Business layer(业务层.模型逻辑) 模型(Model) 模 ...
- mysql笔记之集群
1.主从配置 #主从都要加入以下配置如下 [mysqld] log-bin=mysql-bin #主从要不一样 server-id=222 #在主上建立一个用户给从的用 GRANT REPLICATI ...
- libsdl中文输入法候选列表不显示解决方案
libsdl输入中文时输入法不显示,将WM_IME_SETCONTEXT事件处理给注释即可. WM_IME_SETCONTEXT If the application draws the compos ...
- 01_C语言基础
内容提要: 1. C语言概述2. 数据类型.运算符与表达式3. C语言程序结构 4. VC6.0使用练习 知识详解01:C语言的历史 1. C语言与其它语言比较 汇编语言: (1).可直接对硬件进行操 ...
- ubuntu mint 15 编译安装PHP开发环境
php 5.3.5(download zip) httpd 2.2.24(download zip) mysql: apt-get install mysql step 1: install mysq ...
- 系统监控的一些工具w , vmstat
w 命令:--w 查看的是系统整体上的负载 # w 15:23:46 up 3:34, 2 users, load average: 0.03, 0.05, 0.00 USER TTY FROM LO ...