public JNode VisitMethodGroupResolveResult(MethodGroupResolveResult res) { var info = res.GetInfo(); IMethod me; if (info != null && info.Conversion != null && info.Conversion.Method != null) { me = info.Conversion.Method; } else //happens when invoking a method with overloads, and a parameter is dynamic { var list = res.Methods.ToList(); if (list.Count == 0) { throw new Exception("Method group not resolved to any method"); } else if (list.Count == 1) { me = list[0]; } else { me = list[0]; } //TODO: verify all methods has the same js name } var isExtensionMethodStyle = me.IsExtensionMethod && !(res.TargetResult is TypeResolveResult);//TODO: IsExtensionMethodStyle(new CsInvocationExpression { entity = me, expression = node }); JExpression firstPrm = null; if (isExtensionMethodStyle) { firstPrm = (JExpression)Visit(res.TargetResult); } var node2 = JNaming.JAccess(me); JExpression node3; JExpression instanceContext = null; if (me.IsStatic || res.TargetResult == null) //getting ThisResolveResult even on static methods, getting TargetResult=null when MethodGroupResolveResult when using delegates { node3 = node2; } else { instanceContext = VisitExpression(res.TargetResult); node3 = instanceContext.Member(node2); } if (info != null && (instanceContext != null || firstPrm != null)) { var conv = info.Conversion; if (info.ConversionTargetType != null && !UseNativeFunctions(info.ConversionTargetType))//delegate type { var parentMethod = info.Nodes.FirstOrDefault().GetCurrentMethod(); if (parentMethod == null || !JMeta.ForceDelegatesAsNativeFunctions(parentMethod)) { if (parentMethod == null) { Log.Warn(info.Nodes.FirstOrDefault(), "GetParentMethod() returned null"); } var func = (JExpression)node2; if (instanceContext != null) { node3 = CreateJsDelegate(instanceContext, func); } else if (firstPrm != null) { node3 = CreateJsExtensionDelegate(firstPrm, func); } } } } return(node3); }
JNode CreateJsDelegateIfNeeded(JFunction func, IMember currentMember, IType delType, bool isAnonymous) { if (currentMember != null && !currentMember.IsStatic && !UseNativeFunctions(delType) && !JMeta.ForceDelegatesAsNativeFunctions(currentMember)) { var instanceContext = new JThis(); JExpression wrapper; if (isAnonymous) { wrapper = CreateAnonymousJsDelegate(instanceContext, func); } else { wrapper = CreateJsDelegate(instanceContext, func); } return(wrapper); } else { return(func); } }