Skip to Content
C# 12 核心要点
book

C# 12 核心要点

by Joseph Albahari
May 2025
Intermediate to advanced
1086 pages
14h 54m
Chinese
O'Reilly Media, Inc.
Content preview from C# 12 核心要点

第 19 章 动态编程 动态编程

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

第 4 章介绍了 C# 语言中动态绑定的工作原理。在本章中,我们将简要介绍动态语言运行时(DLR),然后探讨以下动态编程模式:

  • 动态解决成员过载问题

  • 自定义绑定(实现动态对象)

  • 动态语言互操作性

备注

第 24 章中,我们将介绍dynamic 如何改进 COM 的互操作性。

本章中的类型位于System.Dynamic 命名空间中,但CallSite<> 除外,它位于System.Runtime.CompilerServices 中。

动态语言运行时

C# 依赖 DLR 来执行动态绑定。

与它的名字相反,DLR 并不是 CLR 的动态版本。相反,它是一个位于 CLR之上的库,就像System.Xml.dll 等其他库一样。它的主要作用是提供运行时服务,以统一静态和动态类型语言中的动态编程。因此,C#、Visual Basic、IronPython 和 IronRuby 等语言都使用相同的协议来动态调用函数。这样,它们就可以共享库并调用用其他语言编写的代码。

DLR 还使在 .NET 中编写新的动态语言变得相对容易。动态语言作者不必发射中间语言 (IL),而是在表达式树(与我们在第 8 章中谈到的表达式树相同)层次上工作。 System.Linq.Expressions中的表达式树)。

DLR 还确保所有用户都能从调用站点缓存中获益,通过这种优化,DLR 可以避免不必要地重复在动态绑定过程中做出的代价可能很高的成员解析决策。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Programming C# 12

Programming C# 12

Ian Griffiths
C# 12 in a Nutshell

C# 12 in a Nutshell

Joseph Albahari
C# 6 for Programmers, Sixth Edition

C# 6 for Programmers, Sixth Edition

Paul Deitel, Harvey Deitel
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 9798341657038