Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvokeGet with static context fails #26

Open
tpluscode opened this issue Aug 23, 2018 · 2 comments · May be fixed by #27
Open

InvokeGet with static context fails #26

tpluscode opened this issue Aug 23, 2018 · 2 comments · May be fixed by #27

Comments

@tpluscode
Copy link

tpluscode commented Aug 23, 2018

I'm migrating an older projects to .NET Standard. Previously I used ImpromputInterface:

Impromptu.InvokeGet(type.WithStaticContext(), "Context");

Where the type is for example a nested private class within a test fixture:

public class ContextResolverTests
{
    private class GenericType
    {
        private static string Context => "Text";
    }
}

Now I want to target netstandard1.5 so I replaced the original implementation with Dynamitey

var staticContext = InvokeContext.CreateStatic;
return Dynamic.InvokeGet(staticContext(type), "Context");

And it stopped working!

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : 
   'JsonLD.Entities.Tests.ContextResolverTests.GenericType' does not contain a definition for 'Context'

Apparently the class has to be public and cannot be nested. Here's my repository stripped down. I removed everything, all unnecessary code and replaced paket with plain nuget references, to no avail.

does-not-work.zip

But the real kicker is that I tried to reproduce this from scratch and was completely unable to get the same effect. What is going on?

works.zip

@tpluscode
Copy link
Author

Oh, I got something!

In the second attachment all 4 tests pass only when all of them are executed together. And more precisely, when Nested_WithImpromptu runs before Nested_WithDynamitey.

Which means that calling ImpromptuInterface.InvokeExt.InvokeExt.WithStaticContext first is what changes the behaviour of Dynamitey.

@tpluscode
Copy link
Author

One more observation. While trying to debug this I noticed that there already is a similar passing test: TestStaticPropertySetFollowedByGetTest. The differece is that it first sets the property. And indeed, calling setter first does "something" which fixes getting private properties later.

Even more interesting is that getting a public static property fails if it is first set because of this condition, saying cannot explicitly call operator or accessor.

@tpluscode tpluscode linked a pull request Sep 9, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant