TradeResult's props should be nullable.
TradeResult's props should be nullable.
21 Dec 2018, 15:06
Hello there.
I have been experiencing some crashes on the account of using the properties "Position" and "PendingOrder" for handling unsuccessful trade results.
I think that such properties should be nullable, for not all instances of "TradeResult" have them, so we end up a "NullReferenceException".
Replies
oliveira.phc
21 Dec 2018, 15:40
RE:
Panagiotis Charalampous said:
Hi oliveira.phc,
I am not sure what are you referring too. Position and PendingOrder are reference types thus by default nullable. Actually Nullable types in C# are used to extend value types, not reference types.
Best Regards,
Panagiotis
Thanks for your readiness, Panagiotis.
I am sorry for not being able to especify correctly what I want to say. You see, when using an instance of TradeResult, one is led to believe that the properties Position and PendingOrder should always be instances of their respective cognate classes. The property Error, for example, has a type of "ErrorCode?", meaning that it could be null. I think the same should apply to Position and PendingOrder, for I have been experiencing some crashes when trying to deal with them.
@oliveira.phc
PanagiotisCharalampous
21 Dec 2018, 15:51
Hi oliveira.phc,
ErrorCode is of type Enum, therefore a value type, so it has ? to indicate that it is nullable. Position and PendingOrder are reference types therefore can be null by default. So no ? is needed. This is a C# feature, not a cTrader Automate API one. You can read more about types here.
Best Regards,
Panagiotis
@PanagiotisCharalampous
oliveira.phc
28 Dec 2018, 11:59
RE:
Thank you for the tip. I am new to typed programming languages and thought that a type, in order to be possibly null, would require a question mark.
@oliveira.phc
PanagiotisCharalampous
21 Dec 2018, 15:24
Hi oliveira.phc,
I am not sure what are you referring too. Position and PendingOrder are reference types thus by default nullable. Actually Nullable types in C# are used to extend value types, not reference types.
Best Regards,
Panagiotis
@PanagiotisCharalampous