-
Notifications
You must be signed in to change notification settings - Fork 43
Undefined type #56
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
Comments
Hey! Interesting point. I've just taken a look at Jurassic's API, in particular /// <summary>
/// Executes the given source code. Execution is bound to the global scope.
/// </summary>
/// <param name="code"> The javascript source code to execute. </param>
/// <returns> The result of executing the source code. </returns>
/// <exception cref="ArgumentNullException"> <paramref name="code"/> is a <c>null</c> reference. </exception>
public object Evaluate(string code)
{
return Evaluate(new StringScriptSource(code));
}
/// <summary>
/// Executes the given source code. Execution is bound to the global scope.
/// </summary>
/// <typeparam name="T"> The type to convert the result to. </typeparam>
/// <param name="code"> The javascript source code to execute. </param>
/// <returns> The result of executing the source code. </returns>
/// <exception cref="ArgumentNullException"> <paramref name="code"/> is a <c>null</c> reference. </exception>
public T Evaluate<T>(string code)
{
return TypeConverter.ConvertTo<T>(this, Evaluate(code));
} To support returning an instance of a custom type For example, at present, Would that be enough? Anything I missed out? |
For this case, you can implement the |
As an example of how I work with a |
Thanks for the extra info Invoke Methods with Generic Parameters
I'm not sure if I understood you right on this point. I've looked through protected override T InnerEvaluate<T>(string expression, string documentName)
{
object result = InnerEvaluate(expression, documentName);
return TypeConverter.ConvertToType<T>(result);
} It seems to me that PlanWill this plan meet your needs?
public class Undefined
{
internal static readonly Undefined Value = new Undefined();
private Undefined()
{
}
#region Object overrides
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>A string that represents the current object.</returns>
/// <remarks>
/// The <see cref="Undefined"/> version of this method returns "[undefined]".
/// </remarks>
public override string ToString()
{
return "[undefined]";
}
#endregion
}
Also, within the |
Microsoft ClearScript.V8 always returns a value of
The implementation details of this type are not particularly important to me. If a structure is more suitable for you, then implement this type as a structure. Only two things are important to me:
I.e. that there was an opportunity to create the
Non-generic versions of the |
Okay, I believe we're on the same page. This will be a useful addition for those who want to return dynamic objects. Will tag you when I create the PR! |
OK. |
Hello, Jeremy!
In Jering.Javascript.NodeJS values of
null
andundefined
types are always returned asnull
, that causes inconvenience. Most JS engines for .NET has a clearly separation fornull
andundefined
types. As a rule, to representundefined
in .NET is used a custom type (see as examples the ClearScript and Jurassic).The text was updated successfully, but these errors were encountered: