I have the following structure:
abstract class Parent {}
class Child : Parent
{
// Member Variable that I want access to:
OleDbCommand[] _comman
// _commandCollection is an instance, private member
BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
// Retrieve a FieldInfo instance corresponding to the field
FieldInfo field = GetType().GetField("_commandCollection", flags);
// Retrieve the value of the field, and cast as necessary
IDbCommand[] cc =(IDbCommand[])field.GetValue(this);
Array covariance should ensure that the cast is successful.
I assume some designer will be generating the subclasses? Otherwise, a protected property is probably what you're looking for.
It's possible, though it's a decidedly bad idea.
var field = GetType().GetField("_commandCollection", BindingFlags.Instance | BindingFlags.NonPublic);
I think what you really want to do is provide a method for the child classes to provide the parent with the required data:
protected abstract IEnumerable<IDBCommand> GetCommands();