Any Way To Programmatically Detect ReadOnly Properties? 
Author Message
 Any Way To Programmatically Detect ReadOnly Properties?

I'm writing a code-generating app which needs to gracefully continue when
setting object properties when a particular property on an object is
read-only. I know I could add try/catch after every property setting, but
that's pretty ugly. Is there anything like

IsPropertyReadOnly(MyClass.MyProperty)

such that I can avoid exceptions caused by attempting to write to a property
that is read-only?

Note: the objects in question are DSO objects, and the same properties can
be read/write or read-only under varying conditions, not all of which appear
to be well documented.



Wed, 10 Nov 2004 03:00:15 GMT  
 Any Way To Programmatically Detect ReadOnly Properties?


Quote:
> I'm writing a code-generating app which needs to gracefully continue when
> setting object properties when a particular property on an object is
> read-only. I know I could add try/catch after every property setting, but
> that's pretty ugly. Is there anything like

> IsPropertyReadOnly(MyClass.MyProperty)

> such that I can avoid exceptions caused by attempting to write to a
property
> that is read-only?

> Note: the objects in question are DSO objects, and the same properties can
> be read/write or read-only under varying conditions, not all of which
appear
> to be well documented.

With out testing it (I know I should but I'm feeling lazy), you should be
able to do something like this:

if (theObject.GetType().GetProperty("TheProperty").CanWrite)
{
    theObject.TheProperty = TheValue;

Quote:
}

Anyway - HTH,
Tom Shelton


Wed, 10 Nov 2004 03:52:11 GMT  
 Any Way To Programmatically Detect ReadOnly Properties?
Tom

I think that will work, thanks!


Quote:



> > I'm writing a code-generating app which needs to gracefully continue
when
> > setting object properties when a particular property on an object is
> > read-only. I know I could add try/catch after every property setting,
but
> > that's pretty ugly. Is there anything like

> > IsPropertyReadOnly(MyClass.MyProperty)

> > such that I can avoid exceptions caused by attempting to write to a
> property
> > that is read-only?

> > Note: the objects in question are DSO objects, and the same properties
can
> > be read/write or read-only under varying conditions, not all of which
> appear
> > to be well documented.

> With out testing it (I know I should but I'm feeling lazy), you should be
> able to do something like this:

> if (theObject.GetType().GetProperty("TheProperty").CanWrite)
> {
>     theObject.TheProperty = TheValue;
> }

> Anyway - HTH,
> Tom Shelton



Wed, 10 Nov 2004 04:18:34 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help needed badly - In making a property Uneditable or readonly in vb properties window

2. Q?: How to programmatically change Editbox style to READONLY

3. Toggle READONLY property on CEdit()?

4. ReadOnly Property not visible in VB.NET

5. Readonly Property

6. What can I set ReadOnly property for combobox?

7. CLS, naming, underscore, and readonly properties

8. ReadOnly Property

9. ReadOnly Array property?

10. Deafult ReadOnly Interface Properties

11. programmatically detect a comm port assigned to a modem

12. Programmatically detecting modem drivers?

 

 
Powered by phpBB® Forum Software