B
Bob
I want to find a way to detect the existance of the private member of a
particular type in the derived class from inside the base class itself and
call its Dispose() method. Reflection GetFields() only returns public
members and I would like to avoid using reflection due to its performance
impact. Not sure if using an enumerator would help. The code below
illustrates what I want to do. If this is doable, the benefit would be that
there is no need to write the same Dispose code in every derived class that
has the SqlConnection variable.
//Base class
public class MyBase {
..........
public Dispose() {
//if a private field of SqlConnection exists, call its Close()
method
}
}
//Derived class
public class MyClass : MyBase {
.......
//This derived class happen to have a member of the SqlConnection.
//The member name (variable name) may vary in different derived classes.
private SqlConnection _conn;
.......
}
particular type in the derived class from inside the base class itself and
call its Dispose() method. Reflection GetFields() only returns public
members and I would like to avoid using reflection due to its performance
impact. Not sure if using an enumerator would help. The code below
illustrates what I want to do. If this is doable, the benefit would be that
there is no need to write the same Dispose code in every derived class that
has the SqlConnection variable.
//Base class
public class MyBase {
..........
public Dispose() {
//if a private field of SqlConnection exists, call its Close()
method
}
}
//Derived class
public class MyClass : MyBase {
.......
//This derived class happen to have a member of the SqlConnection.
//The member name (variable name) may vary in different derived classes.
private SqlConnection _conn;
.......
}