Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted

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

  • *Experts*
Posted

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

"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
Posted

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.

"Who is John Galt?"

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...