In a project here, we have an Object ClassTest, which has many sub objects:
public class ClassTest
{
public bool[] abTestAvailable = new bool[_TESTS];
public ClassTest_FCT_Extern Test_FCT_Extern = API.Serializer.Load<ClassTest_FCT_Extern>(API.Workstation.strPath_Hardware + "FCT_Extern.xml");
// ...
The idea was now, that Test_FCT_Extern sets abTestAvailable during initialization:
public class ClassTest_FCT_Extern
{
public bool TestAvailable
{
get { return API.Test.abTestAvailable[(int)ClassTest.IndividualTest.FCT_Extern]; }
set { API.Test.abTestAvailable[(int)ClassTest.IndividualTest.FCT_Extern] = value; }
}
But this fails, because during the creation of the API.Test objects, the API.Test.Test_FCT_Extern is created. So, in this moment API.Test still does not exist and the Array abTestAvailable is not yet initialized.
I have found now a solution for our case, but maybe there are smarter ways to access parents parameters.
In our case, the solution was to make the array static:
The static array is initialized before the Objects are created
works fine, without exception.
Moral: make static if possible!