c#4.0新特性之一: Dynamic Lookup (1)
2008-10-29 22:17
363 查看
废话不多说,直接开始。先看程序:
class Program
2
12public class Foo
13.method private hidebysig static void Main(string[] args) cil managed
2{
3 .entrypoint
4 // Code size 205 (0xcd)
5 .maxstack 7
6 .locals init ([0] object foo1)
7 IL_0000: newobj instance void LearnCSharp4.Foo::.ctor()
8 IL_0005: stloc.0
9 IL_0006: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site1'
10 IL_000b: brtrue.s IL_0033
11 IL_000d: call class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder::GetInstance()
12 IL_0012: ldc.i4.0
13 IL_0013: ldc.i4.0
14 IL_0014: ldstr "Do1"
15 IL_0019: ldtoken [mscorlib]System.Object
16 IL_001e: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
17 IL_0023: ldnull
18 IL_0024: newobj instance void [System.Core]Microsoft.CSharp.RuntimeBinder.CSharpCallPayload::.ctor(class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder,
19 bool,
20 bool,
21 string,
22 class [mscorlib]System.Type,
23 class [mscorlib]System.Type[])
24 IL_0029: call class [System.Core]System.Scripting.Actions.CallSite`1<!0> class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Create(class [System.Core]System.Scripting.Actions.CallSiteBinder)
25 IL_002e: stsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site1'
26 IL_0033: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site1'
27 IL_0038: ldfld !0 class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Target
28 IL_003d: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site1'
29 IL_0042: ldloc.0
30 IL_0043: callvirt instance void class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>::Invoke(!0,
31 !1)
32 IL_0048: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site2'
33 IL_004d: brtrue.s IL_0075
34 IL_004f: call class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder::GetInstance()
35 IL_0054: ldc.i4.0
36 IL_0055: ldc.i4.0
37 IL_0056: ldstr "Do2"
38 IL_005b: ldtoken [mscorlib]System.Object
39 IL_0060: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
40 IL_0065: ldnull
41 IL_0066: newobj instance void [System.Core]Microsoft.CSharp.RuntimeBinder.CSharpCallPayload::.ctor(class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder,
42 bool,
43 bool,
44 string,
45 class [mscorlib]System.Type,
46 class [mscorlib]System.Type[])
47 IL_006b: call class [System.Core]System.Scripting.Actions.CallSite`1<!0> class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Create(class [System.Core]System.Scripting.Actions.CallSiteBinder)
48 IL_0070: stsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site2'
49 IL_0075: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site2'
50 IL_007a: ldfld !0 class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Target
51 IL_007f: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site2'
52 IL_0084: ldloc.0
53 IL_0085: callvirt instance void class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>::Invoke(!0,
54 !1)
55 IL_008a: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site3'
56 IL_008f: brtrue.s IL_00b7
57 IL_0091: call class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder::GetInstance()
58 IL_0096: ldc.i4.0
59 IL_0097: ldc.i4.0
60 IL_0098: ldstr "KissFanweixiao"
61 IL_009d: ldtoken [mscorlib]System.Object
62 IL_00a2: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
63 IL_00a7: ldnull
64 IL_00a8: newobj instance void [System.Core]Microsoft.CSharp.RuntimeBinder.CSharpCallPayload::.ctor(class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder,
65 bool,
66 bool,
67 string,
68 class [mscorlib]System.Type,
69 class [mscorlib]System.Type[])
70 IL_00ad: call class [System.Core]System.Scripting.Actions.CallSite`1<!0> class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Create(class [System.Core]System.Scripting.Actions.CallSiteBinder)
71 IL_00b2: stsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site3'
72 IL_00b7: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site3'
73 IL_00bc: ldfld !0 class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Target
74 IL_00c1: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site3'
75 IL_00c6: ldloc.0
76 IL_00c7: callvirt instance void class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>::Invoke(!0,
77 !1)
78 IL_00cc: ret
79} // end of method Program::Main
如果不喜欢看MSIL的话可以这样看:
private static void Main(string[] args)
2{
3{
6{
11{
16 <Main>o__SiteContainer0.<>p__Site3 = CallSite<Action<CallSite, object>>.Create(new CSharpCallPayload(Microsoft.CSharp.RuntimeBinder.RuntimeBinder.GetInstance(), false, false, "KissFanweixiao", typeof(object), null));
17 }
18 <Main>o__SiteContainer0.<>p__Site3.Target(<Main>o__SiteContainer0.<>p__Site3, foo1);
19}
本文旨在为不方便下载和使用vs2010虚拟机朋友帮个忙.
(在后台编辑的时候报stack overflow的问题...无法提交...)
c#4.0新特性之一: Dynamic Lookup (2)
class Program
2
12public class Foo
13.method private hidebysig static void Main(string[] args) cil managed
2{
3 .entrypoint
4 // Code size 205 (0xcd)
5 .maxstack 7
6 .locals init ([0] object foo1)
7 IL_0000: newobj instance void LearnCSharp4.Foo::.ctor()
8 IL_0005: stloc.0
9 IL_0006: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site1'
10 IL_000b: brtrue.s IL_0033
11 IL_000d: call class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder::GetInstance()
12 IL_0012: ldc.i4.0
13 IL_0013: ldc.i4.0
14 IL_0014: ldstr "Do1"
15 IL_0019: ldtoken [mscorlib]System.Object
16 IL_001e: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
17 IL_0023: ldnull
18 IL_0024: newobj instance void [System.Core]Microsoft.CSharp.RuntimeBinder.CSharpCallPayload::.ctor(class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder,
19 bool,
20 bool,
21 string,
22 class [mscorlib]System.Type,
23 class [mscorlib]System.Type[])
24 IL_0029: call class [System.Core]System.Scripting.Actions.CallSite`1<!0> class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Create(class [System.Core]System.Scripting.Actions.CallSiteBinder)
25 IL_002e: stsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site1'
26 IL_0033: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site1'
27 IL_0038: ldfld !0 class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Target
28 IL_003d: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site1'
29 IL_0042: ldloc.0
30 IL_0043: callvirt instance void class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>::Invoke(!0,
31 !1)
32 IL_0048: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site2'
33 IL_004d: brtrue.s IL_0075
34 IL_004f: call class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder::GetInstance()
35 IL_0054: ldc.i4.0
36 IL_0055: ldc.i4.0
37 IL_0056: ldstr "Do2"
38 IL_005b: ldtoken [mscorlib]System.Object
39 IL_0060: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
40 IL_0065: ldnull
41 IL_0066: newobj instance void [System.Core]Microsoft.CSharp.RuntimeBinder.CSharpCallPayload::.ctor(class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder,
42 bool,
43 bool,
44 string,
45 class [mscorlib]System.Type,
46 class [mscorlib]System.Type[])
47 IL_006b: call class [System.Core]System.Scripting.Actions.CallSite`1<!0> class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Create(class [System.Core]System.Scripting.Actions.CallSiteBinder)
48 IL_0070: stsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site2'
49 IL_0075: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site2'
50 IL_007a: ldfld !0 class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Target
51 IL_007f: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site2'
52 IL_0084: ldloc.0
53 IL_0085: callvirt instance void class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>::Invoke(!0,
54 !1)
55 IL_008a: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site3'
56 IL_008f: brtrue.s IL_00b7
57 IL_0091: call class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder::GetInstance()
58 IL_0096: ldc.i4.0
59 IL_0097: ldc.i4.0
60 IL_0098: ldstr "KissFanweixiao"
61 IL_009d: ldtoken [mscorlib]System.Object
62 IL_00a2: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
63 IL_00a7: ldnull
64 IL_00a8: newobj instance void [System.Core]Microsoft.CSharp.RuntimeBinder.CSharpCallPayload::.ctor(class [System.Core]Microsoft.CSharp.RuntimeBinder.RuntimeBinder,
65 bool,
66 bool,
67 string,
68 class [mscorlib]System.Type,
69 class [mscorlib]System.Type[])
70 IL_00ad: call class [System.Core]System.Scripting.Actions.CallSite`1<!0> class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Create(class [System.Core]System.Scripting.Actions.CallSiteBinder)
71 IL_00b2: stsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site3'
72 IL_00b7: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site3'
73 IL_00bc: ldfld !0 class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>>::Target
74 IL_00c1: ldsfld class [System.Core]System.Scripting.Actions.CallSite`1<class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>> LearnCSharp4.Program/'<Main>o__SiteContainer0'::'<>p__Site3'
75 IL_00c6: ldloc.0
76 IL_00c7: callvirt instance void class [System.Core]System.Action`2<class [System.Core]System.Scripting.Actions.CallSite,object>::Invoke(!0,
77 !1)
78 IL_00cc: ret
79} // end of method Program::Main
如果不喜欢看MSIL的话可以这样看:
private static void Main(string[] args)
2{
3{
6{
11{
16 <Main>o__SiteContainer0.<>p__Site3 = CallSite<Action<CallSite, object>>.Create(new CSharpCallPayload(Microsoft.CSharp.RuntimeBinder.RuntimeBinder.GetInstance(), false, false, "KissFanweixiao", typeof(object), null));
17 }
18 <Main>o__SiteContainer0.<>p__Site3.Target(<Main>o__SiteContainer0.<>p__Site3, foo1);
19}
本文旨在为不方便下载和使用vs2010虚拟机朋友帮个忙.
(在后台编辑的时候报stack overflow的问题...无法提交...)
c#4.0新特性之一: Dynamic Lookup (2)
相关文章推荐
- c#4.0新特性之一: Dynamic Lookup (2)
- c#4.0新特性之一: Dynamic Lookup (1)
- C#4.0新特性(1):Dynamic Lookup 动态查找
- c#4.0新特性之一: Dynamic Lookup (2)
- C#4.0新特性:可选参数,命名参数,Dynamic
- C#4.0新特性:可选参数,命名参数,Dynamic
- C#4.0新特性:可选参数,命名参数,Dynamic
- C#4.0新特性:可选参数,命名参数,Dynamic
- C#4.0新特性之二:Named and Optional Parameters
- C#4.0新特性之二:Named and Optional Parameters (2) 剖析篇
- AS3面向对象的特性,其中包括了dynamic解释
- C#4.0新特性之元组Tuple
- C#4.0新特性
- .net 4.0 中的特性总结(一):dynamic
- ASP.NET 3.5 Extensions新特性:ASP.NET Dynamic Data 体验(上)
- C#4.0和VS2010新特性(一)
- .Net 4.0新特性之Dynamic 动态类型(转载)
- C#4.0的dynamic和var及object关键字辨析
- C#一些新特性Object,var,dynamic,asynchronous
- 在Dynamic Data Framework下实现Lookup字段下拉列表模板