You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
c#==================
enum E{a,b }
class A{
public void testFunc(string e){}
public void testFunc(E e){}
}
js=================
var a=new A();
a.testFunc(E.a); // can not find testFunc(E e){}
E.a will convert to double in js
when a.testFunc(E.a); TypeConverter.FindBestMatch can not find a perfect match
but double is close to c# Enum than c# string
=========modified TypeConverter.FindBestMatch seem to solve the issue========
public static IEnumerable FindBestMatch(Engine engine, MethodBase[] methods, JsValue[] arguments)
{
methods = methods
.Where(m => m.GetParameters().Count() == arguments.Length)
.ToArray();
if (methods.Length == 1 && !methods[0].GetParameters().Any())
{
yield return methods[0];
yield break;
}
MethodBase enumMethod = null;
var objectArguments = arguments.Select(x => x.ToObject()).ToArray();
foreach (var method in methods)
{
var perfectMatch = true;
var parameters = method.GetParameters();
for (var i = 0; i < arguments.Length; i++)
{
var arg = objectArguments[i];
var paramType = parameters[i].ParameterType;
if (arg == null)
{
if (!TypeIsNullable(paramType))
{
perfectMatch = false;
break;
}
}
else if (arg.GetType() != paramType)
{
perfectMatch = false;
if(arg.GetType()==typeof(double)&¶mType.IsEnum)
{
enumMethod=method;
}
else
{ enumMethod=null;
break;
}
}
}
if (perfectMatch)
{
yield return method;
yield break;
}
}
if (enumMethod != null)
{
yield return enumMethod;
yield break;
}
foreach (var method in methods)
{
yield return method;
}
}
The text was updated successfully, but these errors were encountered:
changhaohao
changed the title
TypeConverter.FindBestMatch do not math js number back to enum
TypeConverter.FindBestMatch do not match js number back to enum
Jul 2, 2015
c#==================
enum E{a,b }
class A{
public void testFunc(string e){}
public void testFunc(E e){}
}
js=================
var a=new A();
a.testFunc(E.a); // can not find testFunc(E e){}
E.a will convert to double in js
when a.testFunc(E.a); TypeConverter.FindBestMatch can not find a perfect match
but double is close to c# Enum than c# string
=========modified TypeConverter.FindBestMatch seem to solve the issue========
public static IEnumerable FindBestMatch(Engine engine, MethodBase[] methods, JsValue[] arguments)
{
methods = methods
.Where(m => m.GetParameters().Count() == arguments.Length)
.ToArray();
The text was updated successfully, but these errors were encountered: