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对象到底做了什么的更多相关文章

  1. AFNetworking到底做了什么

    写在开头: 作为一个iOS开发,也许你不知道NSUrlRequest.不知道NSUrlConnection.也不知道NSURLSession...(说不下去了...怎么会什么都不知道...)但是你一定 ...

  2. volatile关键字到底做了什么?

    话不多说,直接贴代码 class Singleton { private static volatile Singleton instance; private Singleton(){} //双重判 ...

  3. AFNetworking到底做了什么?(二)

      接着上一篇的内容往下讲,如果没看过上一篇内容可以点这: AFNetworking到底做了什么? 之前我们讲到NSUrlSession代理这一块: 代理8: /* task完成之后的回调,成功和失败 ...

  4. 一个Java对象到底占用多大内存?

    最近在读<深入理解Java虚拟机>,对Java对象的内存布局有了进一步的认识,于是脑子里自然而然就有一个很普通的问题,就是一个Java对象到底占用多大内存? 在网上搜到了一篇博客讲的非常好 ...

  5. 一个Java对象到底占用多大内存

    在网上搜到了一篇博客讲的非常好,里面提供的这个类也非常实用: import java.lang.instrument.Instrumentation; import java.lang.reflect ...

  6. 一个Java对象到底占多大内存

    最近在读<深入理解Java虚拟机>,对Java对象的内存布局有了进一步的认识,于是脑子里自然而然就有一个很普通的问题,就是一个Java对象到底占用多大内存? 在网上搜到了一篇博客讲的非常好 ...

  7. new到底做了什么?

    下面是一个实例化自定义的对象,我们将要对他进行分析 //定义构造函数 function A(){ this.b = 1 //在这个对象里增加一个属性 //不可以拥有返回对象的return语句 } va ...

  8. 一个Java对象到底占多大内存?(转)

    最近在读<深入理解Java虚拟机>,对Java对象的内存布局有了进一步的认识,于是脑子里自然而然就有一个很普通的问题,就是一个Java对象到底占用多大内存? 在网上搜到了一篇博客讲的非常好 ...

  9. MySQL实战 | 01-当执行一条 select 语句时,MySQL 到底做了啥?

    原文链接:当执行一条 select 语句时,MySQL 到底做了啥? 也许,你也跟我一样,在遇到数据库问题时,总时茫然失措,想重启解决问题,又怕导致数据丢失,更怕重启失败,影响业务. 就算重启成功了, ...

随机推荐

  1. keystone系列二:keystone源码分析

    六 keystone架构 6.1 Keystone API Keystone API与Openstack其他服务的API类似,也是基于ReSTFul HTTP实现的. Keystone API划分为A ...

  2. VS 2013 Chrome PPAPI 开发环境

    当前系统版本为 Windows 8.1 x64, Chrome 版本为 50.0 1. 准备工作 下载并安装 Python https://www.python.org/download/ * 必须使 ...

  3. jasper2

    package jasper; import java.io.File;import java.io.FileOutputStream;import java.io.OutputStream;impo ...

  4. MVC小系列(二十二)【MVC的Session超时,导致的跳转问题】

    由于mvc内部跳转机制的问题,它只在当前的action所渲染的view上进行跳转,如果希望在当前页面跳,需要将mvc方法改为js方法: filterContext.Result = new Redir ...

  5. Servlet相关接口和Servlet的生命周期

    http://www.cnblogs.com/luotaoyeah/p/3860292.html Servlet相关接口和Servlet的生命周期 创建一个Servlet类最直接的方式是实现javax ...

  6. ios NSMethodSignature and NSInvocation 消息转发

    1.首先获取消息转发时连个函数内部具体内容 MARK:这里是拿[@"xxxxx" length]调用拿来举例说明 (lldb) po signature <NSMethodS ...

  7. /etc/resolv.conf文件详解

    大家好,今天51开源给大家介绍一个在配置文件,那就是/etc/resolv.conf.很多网友对此文件的用处不太了解.其实并不复杂,它是DNS客户机配置文件,用于设置DNS服务器的IP地址及DNS域名 ...

  8. 一、VSTO概述

    一.什么是VSTO? VSTO = Visual Studo Tools for Office,是.net平台下的Office开发技术.相对于传统的VBA(Visual Basic Applicati ...

  9. C# Unix时间戳转换为时间

    在做一些接口的时候,比如返回数据中有一个时间的属性,它的值是使用Unix时间戳表示的,当我们处理它(保存到本地或者格式化前台展示)时需要转换成日期时间,在此就需要根据时间戳转换为日期时间 (注:Uni ...

  10. PAT_1046 划拳

    啦啦啦.今天晚上火车回学校了.= =还是挺舍不得家里的. 题目描述: 划拳是古老中国酒文化的一个有趣的组成部分.酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字.如果谁比划出的数字 ...