Runtime value to Attribute

  • Thread starter Thread starter caulagi
  • Start date Start date
C

caulagi

Hello!

I want to write -

[Persistent, ReadOnly(form.IsFixedValue)]
public double CycleTime
{
get { return cycletime; }
}

i.e. CycleTime should be readonly or otherwise depending on the value
of form.IsFixedValue (IsFixedValue is a property of the form).

But the above code doesn't work (of course). Is there a way to get it
to work the way I want?

TIA,

Pradip
 
I think you need to provide the setter still otherwise it has to be readonly
all the time.

Ciaran O'Donnell
 
Yes, of course. Assuming I have a setter also in place, how can I make
CycleTime readonly or otherwise, depending on form.IsFixedValue?

TIA,
Pradip
I think you need to provide the setter still otherwise it has to be readonly
all the time.

Ciaran O'Donnell

Hello!

I want to write -

[Persistent, ReadOnly(form.IsFixedValue)]
public double CycleTime
{
get { return cycletime; }
}

i.e. CycleTime should be readonly or otherwise depending on the value
of form.IsFixedValue (IsFixedValue is a property of the form).

But the above code doesn't work (of course). Is there a way to get it
to work the way I want?

TIA,

Pradip
 
AFAIK you can't without some hacking in the component model and
ICustomTypeDescriptor (and this would only affect things like PropertyGrid -
not compiled code). You can (and should), however, simply make the setter
throw an exception (InvalidOperationException) if it is used incorrectly.

Marc
 
Hi,

And throwing an exception is usually fine in the designer because it's caught,
and then displayed in a nice little message box :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top