Overriding a Function in a class...
Overriding a Function in a class...
When you override a Function in X#, what is the code required to call the base function from your override, and may need to pass along parameters as well.
Overriding a Function in a class...
Depending on in which dll the function is defined:
XSharp.RT.Functions.<function name>
XSharp.VO.Functions.<function name>
XSharp.Core.Functions.<function name>
for example XSharp.RT.Functions.AAdd()
XSharp.RT.Functions.<function name>
XSharp.VO.Functions.<function name>
XSharp.Core.Functions.<function name>
for example XSharp.RT.Functions.AAdd()
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Overriding a Function in a class...
I should have been more clear in stating that I want to override a Function or Method inside of a Class definition and call the base method from my override.
In C#, overriding a method and calling its base code looks like this:
I’m trying to understand how to do this same type of construct in X#
In C#, overriding a method and calling its base code looks like this:
Code: Select all
class B : A
{
override void X() {
base.X();
Console.WriteLine("y");
}
}
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
Overriding a Function in a class...
Hi Matt,
Or if you want to keep the Functional look of it:
Ok this was quick and out of the top of my head, hopefully Chris or somebody will chirp in to show the exact details where I went wrong, but this is the basic concept.
HTH,
And from what Chris said:FoxProMatt_MattSlay wrote:I should have been more clear in stating that I want to override a Function or Method inside of a Class definition and call the base method from my override.
In C#, overriding a method and calling its base code looks like this:I’m trying to understand how to do this same type of construct in X#Code: Select all
class B : A { override void X() { base.X(); Console.WriteLine("y"); } }
Depending on in which dll the function is defined:for example XSharp.RT.Functions.AAdd()Code: Select all
XSharp.RT.Functions.<function name> XSharp.VO.Functions.<function name> XSharp.Core.Functions.<function name>
Code: Select all
begin namespace XSharp.RT.VFP
static partial class Functions
static method AAdd() as void
XSharp.RT.Functions.AAdd()
Console.Writeline("y")
return
end class
end namespace
Code: Select all
begin namespace XSharp.RT.VFP
function AAdd() as void
XSharp.RT.Functions.AAdd()
Console.Writeline("y")
return
end namespace
HTH,
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
Overriding a Function in a class...
Maybe like the following:
Code: Select all
CLASS B INHERIT A
OVERRIDE METHOD X() AS VOID
SUPER:X()
Console.WriteLine("y")
RETURN
Overriding a Function in a class...
Matt, just in case this wasn't clear, due to mine and Johan's misunderstanding on what you were asking, it's what Jamal mentioned what you're looking for, the use of "SUPER:" to call a method of a parent class.
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Overriding a Function in a class...
Yes. Indeed his answer with Super:X() was exactly what I was looking for.
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
Overriding a Function in a class...
Hi Matt,
Or if you want to keep the Functional look of it:
Yes that is the short answer. Also look at what I said, I was assuming you want to "override" a X# function, with same name as in VFP, but with totally different behavior, or some extended behavior. Will also have the same effect as SUPER:X(), but with a "Functional" approach.FoxProMatt_MattSlay wrote:Yes. Indeed his answer with Super:X() was exactly what I was looking for.
Code: Select all
begin namespace XSharp.RT.VFP
static partial class Functions
static method AAdd() as void
XSharp.RT.Functions.AAdd() // This is same behavior as SUPER:AAdd()
Console.Writeline("y") // We extended our method/function with a "Method" approach
return
end class
end namespace
Code: Select all
begin namespace XSharp.RT.VFP
function AAdd() as void
XSharp.RT.Functions.AAdd() // Again same behavior as SUPER:AAdd()
Console.Writeline("y") // Same extended functionality, using a functional approach
return
end namespace
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
Overriding a Function in a class...
Something that has to be considered is sublclasses of subclasses...
If you just call: XSharp.RT.Functions.AAdd() , then if you are 3 level deep in subclassing, then you will skip the other levels of the inherited classes and juMP straight to the lowest level that you are basically hard-coding to.
Whereas, if you use Super() at each subclass along the way, you can rest assured that you are not skipping another essential code in the immediate parent class.
I'm sure there could be a time when one *wanted* to have this effect, bu they way I code most of my multi-level inherited classes, I will use Super() to be sure each layer gets called.
If you just call: XSharp.RT.Functions.AAdd() , then if you are 3 level deep in subclassing, then you will skip the other levels of the inherited classes and juMP straight to the lowest level that you are basically hard-coding to.
Whereas, if you use Super() at each subclass along the way, you can rest assured that you are not skipping another essential code in the immediate parent class.
I'm sure there could be a time when one *wanted* to have this effect, bu they way I code most of my multi-level inherited classes, I will use Super() to be sure each layer gets called.
Overriding a Function in a class...
Calling XSharp.RT.Functions.AAdd() has absolutely nothing to do with subclassing, I mentioned it only because I misinterpreted your term "override".
The issue is that DotNet has no concept of functions (in the sense that they live "outside" of a class), so they are implemented actually as methods of a special class in each X# dll. The compiler just hides all those implementation details and allows you to simply call ALen(), while under the hood what you are really calling is XSharp.RT.Functions.AAdd(), where "XSharp.RT.Functions" is the name of that special class, and "ALen" is a method of that class.
If you had redefined ALen() in your own code:
FUNCTION ALen(a AS ARRAY) AS DWORD
// my own version of ALen() for any reason
RETURN 17 // just because
then any of your calls to ALen() in your code would resolve to that version of the function (so you would "override" the standard implementation of the function). In order to call the original version in the X# dll, you would need to call it with the full name mentioned in the beginning.
I hope this clears up the confusion.
The issue is that DotNet has no concept of functions (in the sense that they live "outside" of a class), so they are implemented actually as methods of a special class in each X# dll. The compiler just hides all those implementation details and allows you to simply call ALen(), while under the hood what you are really calling is XSharp.RT.Functions.AAdd(), where "XSharp.RT.Functions" is the name of that special class, and "ALen" is a method of that class.
If you had redefined ALen() in your own code:
FUNCTION ALen(a AS ARRAY) AS DWORD
// my own version of ALen() for any reason
RETURN 17 // just because
then any of your calls to ALen() in your code would resolve to that version of the function (so you would "override" the standard implementation of the function). In order to call the original version in the X# dll, you would need to call it with the full name mentioned in the beginning.
I hope this clears up the confusion.
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu