"tests/build/vscode:/vscode.git/clone" did not exist on "7de731a519c197136df008e2645a931ab7c57a89"
Commit 35dcffb0 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Fixed #355 new Guid

* Guid has a lot of ctor overload, the `byte[]` was being used instead the `string`.
Reorder ctor info before trying to match the parameters.
parent bb722827
......@@ -1258,6 +1258,19 @@ namespace NLua
return instance.CallConstructorInternal(luaState);
}
private static ConstructorInfo[] ReorderConstructors(ConstructorInfo[] constructors)
{
int len = constructors.Length;
if (len < 2)
return constructors;
return constructors.
GroupBy(c => c.GetParameters().Length).
SelectMany(g => g.OrderByDescending(ci => ci.ToString())).
ToArray();
}
private int CallConstructorInternal(LuaState luaState)
{
var klass = _translator.GetRawNetObject(luaState, 1) as ProxyType;
......@@ -1273,7 +1286,7 @@ namespace NLua
luaState.Remove(1);
ConstructorInfo[] constructors = klass.UnderlyingSystemType.GetConstructors();
constructors = ReorderConstructors(constructors);
foreach (var constructor in constructors)
{
bool isConstructor = MatchParameters(luaState, constructor, validConstructor, 0);
......
using System;
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
......@@ -67,9 +67,23 @@ namespace NLua.Method
_lastCalledMethod = new MethodCache();
_isStatic = (bindingType & BindingFlags.Static) == BindingFlags.Static;
_members = GetMethodsRecursively(targetType.UnderlyingSystemType,
MethodInfo [] methods = GetMethodsRecursively(targetType.UnderlyingSystemType,
methodName,
bindingType | BindingFlags.Public);
_members = ReorderMethods(methods);
}
private static MethodInfo[] ReorderMethods(MethodInfo[] m)
{
int len = m.Length;
if (len < 2)
return m;
return m.
GroupBy(c => c.GetParameters().Length).
SelectMany(g => g.OrderByDescending(ci => ci.ToString())).
ToArray();
}
MethodInfo[] GetMethodsRecursively(Type type, string methodName, BindingFlags bindingType)
......
......@@ -2782,6 +2782,20 @@ namespace NLuaTest
}
}
[Test]
public void TestGuid()
{
using (Lua lua = new Lua())
{
lua.LoadCLRPackage();
object o = lua.DoString(@" import ('mscorlib','System')
return Guid('adc70ae1-769e-4ace-aa83-928a604c5739')
")[0];
Assert.AreEqual(new Guid("adc70ae1-769e-4ace-aa83-928a604c5739"), o);
}
}
static Lua m_lua;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment