如何在 C# 4 中创建动态类?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/893423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 08:42:06  来源:igfitidea点击:

How do create a Dynamic class in C# 4?

c#dynamic

提问by Ball

I want to create an object in C# and have it do interesting things based on the name of the non-existent method that gets.

我想在 C# 中创建一个对象,并让它根据获取的不存在方法的名称做一些有趣的事情。

In ruby, this is method_missing. In Perl, this is AUTOLOAD.

在 ruby​​ 中,这是 method_missing。在 Perl 中,这是自动加载。

I can't seem to find the way into System.Dynamic in C#.

我似乎无法在 C# 中找到进入 System.Dynamic 的方法。

采纳答案by Curt Hagenlocher

Try using System.Dynamic.DynamicObjectas a simple starting point and base class. You can find an example at http://winterdom.com/2009/05/dynamicobject-in-c-40.

尝试使用System.Dynamic.DynamicObject作为简单的起点和基类。您可以在http://winterdom.com/2009/05/dynamicobject-in-c-40找到一个示例。