By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

How to detect the existance of a private member from inside the class itself

P: n/a
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()

//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;

Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.