One example of using the DLR in C# is as follows:
dynamic dyn = new MyObject();
dyn.MyMethod(); //resolved at runtime
what would be the equivalent in F#?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
?operator has similar expressive power to thedynamickeyword in C# (but it can be only used for reading of properties, method invocation and setting of properties).There is no built-in implementation that would allow you to dynamically use properties or methods of a .NET class (via Reflection or DLR), but there are some fairly solid implementations from the community. This has been discussed in another SO question before.
There are also implementations of
?that allow you access some common data sources such as SQL databases. For example, this MSDN article includes a definition that allows you to writedb?Query?Foo(1)to call a stored procedure namedFoo.For various other types (such as finding an element in XAML or accessing elements or attributes in XML document), the definition of
?is quite easy to write.