Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which language can change class member dynamically in run time?

I know in Ruby can add and modify method of class dynamically in run time. what about other language? what is C# ,can in this language modify or add some method and ... in run time and dynamically?

like image 523
Sajad Bahmani Avatar asked Dec 21 '25 14:12

Sajad Bahmani


2 Answers

I think you are looking for prototype inheritance. A list of languages is mentioned in the same wikipedia page.

There is a similar question on SO which you can look up.

like image 75
dirkgently Avatar answered Dec 23 '25 02:12

dirkgently


Yes, in C# you can add methods at runtime through reflection and the Emitter object.

In C# 4.0 you can even do it in plain C# code with the Expando object. This is arguably closer to the Ruby way (it's practically a carbon copy if I remember correctly) and a lot easier to use.

Edit: All of this applies to all .NET languages, including VB.Net and F#.

like image 36
Blindy Avatar answered Dec 23 '25 02:12

Blindy