golfnut1969 Posted February 10, 2005 Posted February 10, 2005 I have a property that I want to be protected writable but public readable. Can anyone let me know how this is done? Or possible you can tell me the best way to do this: I have a class that has a property. This property should be ReadOnly to everything except those objects that inherit from it. Thanks in advance! Quote
Napivo1972 Posted February 10, 2005 Posted February 10, 2005 To my knowledge the only way to get this done is using a Sub and a Function Protected Sub SetValue(Value as integer) Public Function GetValue as integer Or possibly a read only or write only property and a function or a sub Quote
*Experts* Nerseus Posted February 11, 2005 *Experts* Posted February 11, 2005 If the property masks a private field, make the field protected - thereby allowing the inheriting code to modify the field directly. Then you only expose the get property publicly. Not quite as clean, but might work out. If you want to wrap the setting of the field in a property, maybe make one a function "SetProp" or another property with a different name. I don't think you can do what you were originally asking directly in .NET though, just workarounds. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
IngisKahn Posted February 11, 2005 Posted February 11, 2005 You have 2 options. One: You can switch to programming in MSIL. Have fun. Two: Start using .NET 2.0, they finally added support for split access properties. Quote "Who is John Galt?"
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.