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

Should not wrap Type instances as TypeReference by default #845

Merged
merged 1 commit into from Mar 4, 2021

Conversation

lahma
Copy link
Collaborator

@lahma lahma commented Feb 28, 2021

I couldn't find a reason why we would want to convert Type instances to TypeReference instances unless it's explicit need for type construction (importNamespace, explicit TypeReference.Create). With this change can now read values like a.GetType().FullName, earlier it was hidden as TypeRefereence which doesn't expose much. Old behavior can still be achieved by engine type mappers / object converters.

The README shows correct ways to achieve this:

and then to assign local namespaces the same way System does it for you, use importNamespace

jint> var Foo = importNamespace('Foo');
jint> var bar = new Foo.Bar();
jint> log(bar.ToString());

adding a specific CLR type reference can be done like this

engine.SetValue("TheType", TypeReference.CreateTypeReference(engine, typeof(TheType)))

But there's unit test cases that relies on auto-wrapping:

 _engine.SetValue("TestStruct", typeof(TestStruct));

So I kept the auto-wrapping when called via engine.SetValue(name, type), but no longer automatic in JsValue.FromObject.

fixes #533

@lahma lahma marked this pull request as ready for review February 28, 2021 16:39
@sebastienros
Copy link
Owner

I'll trust your judgement because this is maybe some of the oldest code that is still remaining.

@sebastienros sebastienros merged commit f5a2abf into sebastienros:dev Mar 4, 2021
@lahma lahma deleted the bugs/type-wrapping branch October 31, 2021 07:43
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 this pull request may close these issues.

NullReferenceException on access of Type property!
2 participants