If you were following ANY of the recognized texts, you would not even ask such a question....
Go get a good book, start at the beginning, read everything, type-in everything, step through everything with your debugger.
If you have questions, please come back and ask...
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009 In theory, there is no difference between theory and paractice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
no you can't conditionally expose them, but you can make them invisible to intellisense (though users will still be able to access the public members, it won't show up in intellisense. It will show up in the object browser, reflector, and other class documentation).
you can also use internal which allows classes of the same assembly (you can also make internals visible to other external assemblies thorough an assembly level attribute), but anyone using a reference to your assembly will not.
you could conditionally expose members through use of multiple interfaces, by exposing the instance as an instance of a particular interface:
Code:
public interface IA {
string A { get; set; }
}
public interface IB {
string B { get; }
}
public interface IC {
string C { get; set; }
}
public class Foo : IA, IB, IC {
string a, b, c;
public string A { get { return a; } set { a = value; } }
public string B { get { return b; } }
public string C { get { return c; } set { c = value; } }
}
// ...
if(someCondition) ((IA)instanceOfFoo).A = "asdf"; // B and C are not included
else if(someOtherCondition) string fooB = ((IB)instanceOfFoo).B; // A and C are not included
else if(yetAnotherCondition) ((IC)instanceOfFoo).C = "qwerty"; // A and B are not included
Last edited by MadHatter; January 19th, 2009 at 08:11 PM.
If you were following ANY of the recognized texts, you would not even ask such a question....
I believe this is a direct quote from the movie Harry Potter.
To expand just a little on the topic of this thread. Why do you want to conditionally expose properties anyway? Is this for like some kind of plugin architecture?
Bookmarks