[C# 4.0] 1. Dynamic
2010-09-30 21:04:24 来源:WEB开发网不管兜多大的圈子,最终还是回到反射和表达式编译等 "传统" 技术上。不过相比较而言,Deleage.Compile() 后的委托直接调用自然比反射要快些,更何况 dynamic 编译的代码中还增加了 Cache 处理,因此性能应该还可以。
利用 SOS.dll,我们看看这个生成的动态委托是啥样的。
!name2ee Learn.CUI.exe Learn.CUI.Program+<Main>o__SiteContainer0
Module: 00a12e8c
Assembly: Learn.CUI.exe
Token: c661cc2302000004
MethodTable: 00a14c00
EEClass: 00a11628
Name: Learn.CUI.Program+<Main>o__SiteContainer0
!dumpclass 00a11628
Class Name: Learn.CUI.Program+<Main>o__SiteContainer0
mdToken: c661caf302000004
File: d:\system\my documents\visual studio 2010\Projects\...\Learn.CUI.exe
Parent Class: 798e4454
Module: 00a12e8c
Method Table: 00a14c00
Vtable Slots: 4
Total Method Slots: 4
Class Attributes: 100183 Abstract,
Transparency: Critical
NumInstanceFields: 0
NumStaticFields: 1
MT Field Offset Type VT Attr Value Name
60fa9280 4000001 4 ...lib]], mscorlib]] 0 static 00cb6b70 <>p__Site1
!do 00cb6b70
Name: System.Runtime.CompilerServices.CallSite`1[[System.Action`2[[System.Runtime.CompilerServices.CallSite, System.Core],[System.Object, mscorlib]], mscorlib]]
MethodTable: 60fa9280
EEClass: 60e10ff4
Size: 24(0x18) bytes
File: C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll
Fields:
MT Field Offset Type VT Attr Value Name
60fa8fb0 40006e5 4 ...es.CallSiteBinder 0 instance 00c8baf4 _binder
79be168c 40006e6 8 System.Boolean 1 instance 0 _match
612f0768 40006e4 bc ...ore]], mscorlib]] 0 static c661d13300000000 _SiteCtors
79bdbdd0 40006e7 c System.__Canon 0 instance 00d3caf8 Target
79baab7c 40006e8 10 System.Object[] 0 instance 00d3dbbc Rules
79bdbdd0 40006e9 4 System.__Canon 0 static dynamic statics NYI _CachedUpdate
79bdbdd0 40006ea 8 System.__Canon 0 static dynamic statics NYI _CachedNoMatch
60fae1c0 40006eb c ...on, System.Core]] 0 static dynamic statics NYI CS{$selection}lt;>9__CachedAnonymousMethodDelegate2
60fae1c0 40006ec 10 ...on, System.Core]] 0 static dynamic statics NYI CS{$selection}lt;>9__CachedAnonymousMethodDelegate5
60faeb94 40006ed 14 ...on, System.Core]] 0 static dynamic statics NYI CS{$selection}lt;>9__CachedAnonymousMethodDelegate6
更多精彩
赞助商链接