Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you implement C#4's IDynamicObject interface?

To implement "method-missing"-semantics and such in C# 4.0, you have to implement IDynamicObject:

public interface IDynamicObject
{
  MetaObject GetMetaObject(Expression parameter);
}

As far as I can figure out IDynamicObject is actually part of the DLR, so it is not new. But I have not been able to find much documentation on it.

There are some very simple example implementations out there (f.x. here and here), but could anyone point me to more complete implementations or some real documentation?

Especially, how exactly are you supposed to handle the "parameter"-parameter?

like image 705
Rasmus Faber Avatar asked Oct 29 '08 06:10

Rasmus Faber


People also ask

How is C implemented?

A standard conforming C implementation consists of a compiler that translates compilation units as mandated by the standard, an implementation of the standard library for all functions required by the standard and something (normally a linker) that puts everything together to build an executable file.

Can we implement class in C?

The basic idea of implementing a class in C is to group the data for a C object into structs so that you can have any number of objects. The struct is declared in the . h file so that it is shared between the class and its clients. In addition, you usually need a function that initializes the objects in the class.

What language is C implemented in?

The origin of C is closely tied to the development of the Unix operating system, originally implemented in assembly language on a PDP-7 by Dennis Ritchie and Ken Thompson, incorporating several ideas from colleagues.

Why was C implemented?

C was designed as a minimalist language to be used in writing operating systems for minicomputers, such as the DEC PDP 7, which had very limited memories compared with the mainframe computers of the period. The language was devised during 1969–73, alongside the early development of the UNIX operating system.


1 Answers

The short answer is that the MetaObject is what's responsible for actually generating the code that will be run at the call site. The mechanism that it uses for this is LINQ expression trees, which have been enhanced in the DLR. So instead of starting with an object, it starts with an expression that represents the object, and ultimately it's going to need to return an expression tree that describes the action to be taken.

When playing with this, please remember that the version of System.Core in the CTP was taken from a snapshot at the end of August. It doesn't correspond very cleanly to any particular beta of IronPython. A number of changes have been made to the DLR since then.

Also, for compatibility with the CLR v2 System.Core, releases of IronPython starting with either beta 4 or beta 5 now rename everything in that's in the System namespace to be in the Microsoft namespace instead.

like image 127
Curt Hagenlocher Avatar answered Oct 07 '22 02:10

Curt Hagenlocher