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
3c075f4f
Commit
3c075f4f
authored
Oct 17, 2015
by
Jose Castorena
Browse files
This should allow objects to call base class extension methods
parent
ad5a33c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Core/NLua/Extensions/GeneralExtensions.cs
View file @
3c075f4f
...
@@ -160,7 +160,7 @@ namespace NLua.Extensions
...
@@ -160,7 +160,7 @@ namespace NLua.Extensions
where
extensionType
.
IsSealed
()
&&
!
extensionType
.
IsGenericType
()
&&
!
extensionType
.
IsNested
where
extensionType
.
IsSealed
()
&&
!
extensionType
.
IsGenericType
()
&&
!
extensionType
.
IsNested
from
method
in
extensionType
.
GetMethods
(
BindingFlags
.
Static
|
BindingFlags
.
Public
)
from
method
in
extensionType
.
GetMethods
(
BindingFlags
.
Static
|
BindingFlags
.
Public
)
where
method
.
IsDefined
(
typeof
(
ExtensionAttribute
),
false
)
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
;
select
method
;
return
query
.
ToArray
<
MethodInfo
>
();
return
query
.
ToArray
<
MethodInfo
>
();
}
}
...
...
tests/LuaTests.cs
View file @
3c075f4f
...
@@ -113,11 +113,35 @@ namespace NLuaTest
...
@@ -113,11 +113,35 @@ namespace NLuaTest
public
static
class
VectorExtension
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
;
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
]
[
TestFixture
]
#
if
MONOTOUCH
#
if
MONOTOUCH
...
@@ -2242,13 +2266,34 @@ namespace NLuaTest
...
@@ -2242,13 +2266,34 @@ namespace NLuaTest
var
v
=
(
Vector
)
lua
[
"v"
];
var
v
=
(
Vector
)
lua
[
"v"
];
double
len
=
v
.
Leng
h
t
();
double
len
=
v
.
Lengt
h
();
lua
.
DoString
(
" v:Leng
h
t() "
);
lua
.
DoString
(
" v:Lengt
h
() "
);
lua
.
DoString
(
@" len2 = v:Leng
h
t()"
);
lua
.
DoString
(
@" len2 = v:Lengt
h
()"
);
double
len2
=
(
double
)
lua
[
"len2"
];
double
len2
=
(
double
)
lua
[
"len2"
];
Assert
.
AreEqual
(
len
,
len2
,
"#1"
);
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
]
[
Test
]
public
void
TestOverloadedMethods
()
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