public static JSValue AddClrObject(this JSObject target, IJSService value) { JSContext context = target.Context; var jobj = new JSObject(context); context.SetJSPropertyValue("__clr__obj", jobj); var methods = value .GetType() .GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance) .ToList(); var properties = value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var item in methods) { try { JSClrFunction clrFunction = new JSClrFunction(context, (x) => { // map parameters return(item.Invoke(value, item .GetParameters() .Select((p, i) => (x[i] is JSValue jv) ? jv.ToType(p.ParameterType) : null).ToArray())); }); jobj.InvokeProperty($"__{item.Name}", clrFunction); var r = context.ExecuteScript($"__paramArrayToArrayParam(__clr__obj,__clr__obj.__{item.Name})", "AddClrObject", 0); jobj.InvokeProperty(item.Name.ToCamelCase(), (Java.Lang.Object)r); }
public CompareProductsComponentService(CatalogSettings catalogSettings, IHttpContextAccessor httpContextAccessor, IProductService productService, IJSService jsService) { this._catalogSettings = catalogSettings; this._httpContextAccessor = httpContextAccessor; this._productService = productService; this._jsService = jsService; }