-
Notifications
You must be signed in to change notification settings - Fork 79
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
Utils.createHostFunction and casted delegates #10
Comments
Thanks for reporting this issue, it should be fixxed in commit a77557f by adding a function in IronJS.Native.Utils called createHostFunctionDynamic which takes a System.Delegate as last argument and uses reflection to resolve all types. |
Also, here's an example of it would look when used:
|
Many thanks for the very quick fix! But I think you forgot to upload the latest FSKit changes :) |
Pushed latest FSKit now :) |
Also note that I changed the fix around a bit, so just call createHostFunction like you use to and it will check if the argument is "System.Delegate" and invoke createHostFunctionDynamic by itself. |
…Delegate), added Utils.createHostFunctionDynamic which is statically typed to Delegate and resolves all HostFunction<_> types by using reflection.
Hi,
first, thank you for this awesome code :)
I have found an annoying limitation. If the delegate at createHostFunction is casted to a Delegate it throws a NullReferenceException.
Utils.createHostFunction(env, (Delegate)new Action(this.test));
A quick fix from this:
ArgTypes = FSKit.Reflection.getDelegateArgTypesT<'a>
ReturnType = FSKit.Reflection.getDelegateReturnTypeT<'a>
to this:
ArgTypes = FSKit.Reflection.getDelegateArgTypes(delegate'.GetType())
ReturnType = FSKit.Reflection.getDelegateReturnType(delegate'.GetType())
doesn't help.
I am trying to bind dynamically methods of an object to js functions with Delegate.CreateDelegate like so:
List args = new List(method.GetParameters().Select(p => p.ParameterType));
Type delegateType;
if(method.ReturnType == typeof(void))
{
delegateType = Expression.GetActionType(args.ToArray());
}
else
{
args.Add(method.ReturnType);
delegateType = Expression.GetFuncType(args.ToArray());
}
The text was updated successfully, but these errors were encountered: