Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
081b78c7
Commit
081b78c7
authored
Oct 19, 2015
by
Vinicius Jarina
Browse files
Merge pull request #182 from Dynameter/base_class_extensions
This should allow objects to call base class extension methods
parents
ad5a33c0
3c075f4f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Core/NLua/Extensions/GeneralExtensions.cs
View file @
081b78c7
...
...
@@ -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
>
();
}
...
...
tests/LuaTests.cs
View file @
081b78c7
...
...
@@ -113,11 +113,35 @@ namespace NLuaTest
public
static
class
VectorExtension
{
public
static
double
Leng
h
t
(
this
Vector
v
)
public
static
double
Lengt
h
(
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
.
Leng
h
t
();
lua
.
DoString
(
" v:Leng
h
t() "
);
lua
.
DoString
(
@" len2 = v:Leng
h
t()"
);
double
len
=
v
.
Lengt
h
();
lua
.
DoString
(
" v:Lengt
h
() "
);
lua
.
DoString
(
@" len2 = v:Lengt
h
()"
);
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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment