Commit 3c075f4f authored by Jose Castorena's avatar Jose Castorena
Browse files

This should allow objects to call base class extension methods

parent ad5a33c0
......@@ -160,7 +160,7 @@ namespace NLua.Extensions
where extensionType.IsSealed() && !extensionType.IsGenericType() && !extensionType.IsNested
from method in extensionType.GetMethods (BindingFlags.Static | BindingFlags.Public)
where method.IsDefined (typeof (ExtensionAttribute), false)
where method.GetParameters () [0].ParameterType == type
where (method.GetParameters () [0].ParameterType == type || type.IsSubclassOf(method.GetParameters()[0].ParameterType))
select method;
return query.ToArray<MethodInfo> ();
}
......
......@@ -113,11 +113,35 @@ namespace NLuaTest
public static class VectorExtension
{
public static double Lenght (this Vector v)
public static double Length (this Vector v)
{
return v.x * v.x + v.y * v.y;
}
}
#if MONOTOUCH
[Preserve (AllMembers = true)]
#endif
public class Person
{
public string firstName;
}
#if MONOTOUCH
[Preserve (AllMembers = true)]
#endif
public class Employee : Person
{
public string occupation;
}
public static class PersonExentsions
{
public static string GetFirstName (this Person argPerson)
{
return argPerson.firstName;
}
}
[TestFixture]
#if MONOTOUCH
......@@ -2242,13 +2266,34 @@ namespace NLuaTest
var v = (Vector)lua ["v"];
double len = v.Lenght ();
lua.DoString (" v:Lenght() ");
lua.DoString (@" len2 = v:Lenght()");
double len = v.Length ();
lua.DoString (" v:Length() ");
lua.DoString (@" len2 = v:Length()");
double len2 = (double)lua ["len2"];
Assert.AreEqual (len, len2, "#1");
}
}
[Test]
public void TestBaseClassExtensionMethods ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString (@" import ('NLuaTest')
p = Employee()
p.firstName = 'Paulo'
p.occupation = 'Programmer'");
var p = (Person)lua ["p"];
string name = p.GetFirstName();
lua.DoString (" p:GetFirstName() ");
lua.DoString (@" name2 = p:GetFirstName()");
string name2 = (string)lua ["name2"];
Assert.AreEqual (name, name2, "#1");
}
}
[Test]
public void TestOverloadedMethods ()
......
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