Closed sergioamm17 closed 10 months ago
Hi @sergioamm17,
We're assuming that IM
is a host object. If that's correct, how are the Reference
and Origin
properties defined in managed code?
Also, what is Namespace.MyObject
? If that's a host object or type, how are you exposing it to the script engine?
Thanks!
Yes, the IM is a host object.
This is the Origin
property
private MyCustomObject _origin; public MyCustomObject Origin { get { return _origin; } set { _origin = value; } }
And the Reference
property
public string Reference { get { return Convert.ToString(Entity.iProperties[MemberName.Reference]); } set { Entity.iProperties[MemberName.Reference] = value; } }
Reference is working as expected, however, the Origin is not working at all. I think the reason is because is an complex type (my custom object)
Namespace.MyObject
is the namespace and name of my custom class, for example MyCustomObject
according to the shared example. I already registered my custom type using Engine.AddHostType("MyTypes", typeof(Namespace.MyCustomObject));
I want to set the new value for the Origin property from the script.
Hello @sergioamm17,
I already registered my custom type using
Engine.AddHostType("MyTypes", typeof(Namespace.MyCustomObject));
I want to set the new value for the Origin property from the script.
Given that AddHostType
call, the JavaScript expression new MyTypes()
should create a MyCustomObject
instance (assuming that MyCustomObject
has a parameterless constructor).
Can you verify that?
Yes, my class MyCustomObject
already has a parameterless constructor.
I made a couple of more tests and it looks the type of the property Origin is not registered at all. This should be why I can not assign a new object to the property, even if I create another object type, it's not the same as the property and that throws the exception.
So far, I need to fix a namespaces error, to register succesfully the Origin Type.
This is a shared project between a big team, that's why I'm trying to fix this kind of programming errors. Thanks for your help, you made me understand the issue.
Please reopen this issue if you have additional questions or comments about this topic. Thank you!
Currently I have an object reference inside the script For example
IM.Reference or IM.Origin
If I send a value from the code, within the script we can access the value, However, if we want to assign a value from the script we can do this:IM.Reference = "somthing"
it works because is a string or primitive typeIM.Origin = new Namespace.MyObject()
this doesn't work as expected, even if I use the HostFunction include in the library. This does not work eitherIM.Origin = host.newObj(Namespace.MyObject);
I need help to create a new instance or object of my type and then assign properties to the object. My property Origin is public and we have implemented the get and set methods to see if it works but never hit the debugger.
The current error I'm getting is:
Invalid property assignment