NiL.JS
NiL.JS copied to clipboard
Please help List auto convert to Array
engine.DefineVariable("myCallObject").Assign(JSValue.Marshal(new MyCallObject));
public class MyCallObject {
public List<string> GetListObject() {
return new List<string>();
}
}
engine.Eval(@"
var list = myCallObject.GetListObject(); //------------------ Get Generic List
var count = list.Count // ------------------------ Get Count from generic = undefined
var length = list.length // ------------------------ this works fine (list is js array)
")
why the engine translates generic into array. How can I make it so that there remains Marshal to Generic thanks for answer!!!
You can change type of result of GetListObject with JSValue and use Wrap for wrap result of it. If it possible, of course. Else you can use ConvertValueAttribute with this example https://github.com/nilproject/NiL.JS/blob/version-2.5/Examples/5.%20Namespaces%20and%20external%20types/Using%20attributes.cs
I think in most cases there will be a relatively stable set of types people will convert between, such as arrays, Lists, and Dictionaries. I think it would make more sense to have a single point of conversion handling than to have every property decorated to point to a converter?
I think we need a way of allowing users to extending the marshalling. I just noticed at GUIDs are not marshalled, so even though most people want them as strings, they are currently inaccessible unless suffixed with .ToString() (not .toString()).
@jsobell yes, it will be a good feature. I will make it when there is free time.
We would like to register specific converter. eg: convert JSObject to IDictionary<string,object> and vice versa.
We can't use attributes and don't want to provide custom JSValue objects for every dotnet object.