Wayne O Wayne O - 1 month ago 11
C# Question

Why can't my C++ code see this C# class member?

I have several custom classes in a C# project that I then reference in a C++ project. The C# code looks something like this

namespace AllOptions
{
public class AllOptions {
public AlgorithmOptions algOptions{ get; set; }
public DatabaseOptions dataOptions{ get; set; }
}

public class AlgorithmOptions {
List<Algorithm> algorithms { get; set; }

public void SetDefaults(){
this.algorithms.Clear();
}
}
public class Algorithm {
public bool AllowSalt { get; set; }
}
public class DatabaseOptions {
public List<string> databaseSrouces { get; set; }
}
}


And then from C++ I am trying to access the various parts of the AllOptions but not all of them are coming through.

//Is declared at the beginning
public: VerifyOptions::VerifyOptions Options;

//Then later on I try to access the database options and algorithm options
this->Options.databaseOptions->databaseSources = someStringList; //works fine

//This cannot find the algorithm list
this->Options.algorithmOptions->algorithms = someAlgorithmList; //does not work


The algorithms says "Class AllOptions::AlgorithmOptions has no member algorithms". Why can't the C++ code see this particular C# member?

EDIT My question was tagged as a possible duplicate to this Default access modifier in C# question. However I believe these to be different questions that happened to result in the same answer. If I am wrong in thinking that please tag it again and I will change it.

Answer

AlgorithmOptions.algorithms is a private member. Only the containing class can access its private members. In contrast, DatabaseOptions.databaseSources is a public member, and you can access it from anywhere.

Comments