question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DLR/dynamic support

See original GitHub issue

Hi, Is there a way to make FluentAssertions work with dynamic/DLR? Consider the following code:

dynamic expando = new ExpandoObject();
expando.someVar = "string";
expando.someVar.Should().Be("string");

which throws Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “‘string’ does not contain a definition for ‘Should’”

Thanks!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
lycandroidcommented, Jul 4, 2019

I am using cast to object as a workaround, but where I am specifically wanting to test the type of a dynamic e.g.

// field.value is dynamic
field.value = "xyz";
((object)field.value).Should().BeOfType(typeof(string));

FWIW the same cast would work for the OP

 ((object)expando.someVar).Should().Be("string");
2reactions
dennisdoomencommented, Feb 18, 2015

Not until C# supports calling extension methods from dynamic objects…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Language Runtime
The Dynamic Language Runtime (DLR) from Microsoft runs on top of the Common Language Runtime (CLR) and provides computer language services for dynamic...
Read more >
Dynamic Language Runtime Overview - .NET Framework
The DLR adds dynamic objects to C# and Visual Basic to support dynamic behavior in these languages and enable their interoperation with dynamic...
Read more >
Grokking the DLR: Why it's Not Just for Dynamic Languages
With dynamic type support now baked into C# and Visual Basic, the DLR has become a gateway from our favorite .NET languages to...
Read more >
Exploring the Dynamic Language Runtime in .Net
The DLR (Dynamic Language Runtime) runs on top of the CLR (Common ... The services provided by the DLR include support for a...
Read more >
What is Dynamic Language Runtime (DLR)
The DLR introduces dynamic objects to C# and Visual Basic in Visual Studio 2010 to support dynamic behavior in these languages and enable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found