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

How to invoke a method that implicit cast string, such as XElment.Elements(XName name) #115

Closed
dwanboweb opened this issue May 17, 2019 · 3 comments
Assignees

Comments

@dwanboweb
Copy link

Firstly,I try to use Linq xml in my Script,such as:
var XDocument=clr.System.Xml.Linq.XDocument var doc = XDocument.Load(xmlPath); var root = doc.Root; var patients = root.Elements('patient');
And it makes error.It seems that 'string' cannot be implicit to the 'XName'.
So I have to write as
var patients = root.Elements(Lib.GetXName('patient'));
public XName GetXName(string name) { return (XName)name; }
Is there any more elegant way?As 'XName' is used frequently.
Thank you very much

@ClearScriptLib ClearScriptLib changed the title How to invoke a method that implicit cast string,such as XElment.Elements(XName name) How to invoke a method that implicit cast string, such as XElment.Elements(XName name) May 17, 2019
@ClearScriptLib ClearScriptLib self-assigned this May 17, 2019
@ClearScriptLib
Copy link
Collaborator

ClearScriptLib commented May 17, 2019

Hi @dwanboweb,

Currently ClearScript doesn't support implicit conversion operators for method arguments. Specifically, the call binds to the correct method, but ClearScript's invocation code can't perform the required conversion. We'll add that capability in the next release.

What you're doing is exactly the workaround we'd recommend. You could make the conversion syntax slightly simpler by providing a wrapper function or extending the String prototype, but that's really a matter of preference; for now, unfortunately, you must do the conversion explicitly.

Thanks for reporting this!

ClearScriptLib added a commit that referenced this issue Aug 1, 2019
…y, GitHub Issue #114); added initial support for CommonJS modules (V8 and JScript); added ScriptEngine.ExecuteDocument and ScriptEngine.EvaluateDocument; added V8ScriptEngine.CompileDocument and V8Runtime.CompileDocument; added support for machine-level deployment (GitHub Issue #117); added Extensions and JavaScriptExtensions to facilitate specific scenarios; added implicit conversion of host method arguments via user-defined operators (GitHub Issue #115); patched a V8 issue that causes occasional script execution failure in 32-bit processes (GitHub Issue #111); fixed accessibility of public methods overriden by internal classes (GitHub Issue #112); updated deployment and API documentation. Tested with V8 7.6.303.28.
@ClearScriptLib
Copy link
Collaborator

ClearScript 5.6 adds support for implicit conversion operators for host method arguments.

@dwanboweb
Copy link
Author

wow ,I just need this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants