Why is FunctionSimple Indexed?  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
User avatar
orad
Posts: 121
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 20 times

Why is FunctionSimple Indexed?

Postby orad » 19 Jan 2015

Hi,

I was working on a FunctionSimple<T> class and I hit exceptions. When I did more debugging I figured that I was referencing bars back and had to use FunctionSeries<T> instead. But I'm wondering if FunctionSimple<T> class is supposed to not reference values of previous bars, then why does it have indexers at all?! I would expect that if I use 'this[1]' in a FunctionSimple<T> declaration then it should give a compile error.

To try this you can use the following code (borrowed from here and changed FunctionSeries to FunctionSimple):

Code: Select all

public class CurrentBar : FunctionSimple<int>
{
public CurrentBar(CStudyControl master) : base(master){}

protected override int CalcBar(){
return this[1] + 1;
}
}
Thanks!

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Why is FunctionSimple Indexed?  [SOLVED]

Postby Henry MultiСharts » 22 Jan 2015

Hello orad,

It is an implementation peculiarity. Both FunctionSimple and FunctionSeries are inherited from common interface, but implement it differently according to their goals.

User avatar
orad
Posts: 121
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 20 times

Re: Why is FunctionSimple Indexed?

Postby orad » 22 Jan 2015

Thank you Henry. This clarifies that we should not use indexers on FunctionSimple<T> or VariableObject<T>.

User avatar
orad
Posts: 121
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 20 times

Re: Why is FunctionSimple Indexed?

Postby orad » 22 Jan 2015

By the way, I think there is a workaround for this. You might be able to use the new keyword on the derived class to hide it by changing it's access modifier to private. I'm not sure if this is recommended but you can try.

See on MSDN: Hiding through inheritance

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Why is FunctionSimple Indexed?

Postby Henry MultiСharts » 22 Jan 2015

By the way, I think there is a workaround for this. You might be able to use the new keyword on the derived class to hide it by changing it's access modifier to private. I'm not sure if this is recommended but you can try.

See on MSDN: Hiding through inheritance
Thank you for the suggestion. It has been forwarded to our developers.


Return to “MultiCharts .NET”