public JsExpression TryTranslateCall(HalfTranslatedExpression context, HalfTranslatedExpression[] args, MethodInfo method) { if (method == null) { return(null); } { if (MethodTranslators.TryGetValue(method, out var translator) && translator.TryTranslateCall(context, args, method) is JsExpression result) { return(result); } } if (method.IsGenericMethod) { var genericMethod = method.GetGenericMethodDefinition(); if (MethodTranslators.TryGetValue(genericMethod, out var translator) && translator.TryTranslateCall(context, args, method) is JsExpression result) { return(result); } } foreach (var iface in method.DeclaringType.GetInterfaces()) { if (Interfaces.Contains(iface)) { var map = method.DeclaringType.GetTypeInfo().GetRuntimeInterfaceMap(iface); var imIndex = Array.IndexOf(map.TargetMethods, method); if (imIndex >= 0 && MethodTranslators.TryGetValue(map.InterfaceMethods[imIndex], out var translator) && translator.TryTranslateCall(context, args, method) is JsExpression result) { return(result); } } } if (method.DeclaringType.GetTypeInfo().IsGenericType&& !method.DeclaringType.GetTypeInfo().IsGenericTypeDefinition) { var genericType = method.DeclaringType.GetGenericTypeDefinition(); var m2 = genericType.GetMethod(method.Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (m2 != null) { var r2 = TryTranslateCall(context, args, m2); if (r2 != null) { return(r2); } } } if (method.DeclaringType == typeof(Array)) { var m2 = typeof(Array).GetMethod(method.Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (m2 != null) { var r2 = TryTranslateCall(context, args, m2); if (r2 != null) { return(r2); } } } var baseMethod = method.GetBaseDefinition(); if (baseMethod != null && baseMethod != method) { return(TryTranslateCall(context, args, baseMethod)); } else { return(null); } }
public JsExpression TryTranslateCall(HalfTranslatedExpression context, HalfTranslatedExpression[] arguments, MethodInfo method) => Translators.Select(t => t.TryTranslateCall(context, arguments, method)).FirstOrDefault(d => d != null);
public JsExpression TryTranslateCall(HalfTranslatedExpression context, HalfTranslatedExpression[] arguments, MethodInfo method) => TryTranslateDelegate(context, arguments, method);