NiL.JS icon indicating copy to clipboard operation
NiL.JS copied to clipboard

Please help List auto convert to Array

Open alexhome82 opened this issue 7 years ago • 5 comments

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!!!

alexhome82 avatar Apr 11 '18 19:04 alexhome82

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

nilproject avatar Apr 12 '18 12:04 nilproject

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?

jsobell avatar Apr 13 '18 23:04 jsobell

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 avatar Apr 16 '18 10:04 jsobell

@jsobell yes, it will be a good feature. I will make it when there is free time.

nilproject avatar Apr 16 '18 11:04 nilproject

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.

viceice avatar Feb 05 '20 11:02 viceice