0

In our code we have a ViewModel object that has a decorator as follows:

[Editable(true)]
public double Price { get; set; }

Does this decorator actually do anything? It seems like it is editable regardless.

I found the documentation here: https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.editableattribute%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

But it really doesn't help much with usage as it has bad descriptions and no examples.

Cory-G
  • 1,025
  • 14
  • 26

2 Answers2

1

Oh, never mind. I should have read the properties and functions section of the documentation. It looks like it add those properties and functions, but those behave differently based on what you set editable to:

https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.editableattribute%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

Properties

AllowEdit - Gets a value that indicates whether a field is editable.

AllowInitialValue - Gets or sets a value that indicates whether an initial value > is enabled.

...

Cory-G
  • 1,025
  • 14
  • 26
  • "This class neither enforces nor guarantees that a field is editable. The underlying data store might allow the field to be changed regardless of the presence of this attribute." – r3bel Mar 14 '17 at 19:51
  • @r3bel I didn't say it did. You have to check those things yourself, but it adds the properties for you to make it easier to check edit-ability. – Cory-G Mar 14 '17 at 20:00
0

No, but It could be usefull if you want to make non-editable a field like this:

[Editable(false)]

but if you want to make non-editable a field, you should use ReadOnly like this:

[ReadOnly(true)]

So... It does not do anything.

lem2802
  • 1,152
  • 7
  • 18
  • 1
    Saying it does *nothing* is misleading. This attribute is used by the [`DataAnnotationsModelMetadataProvider`.](https://referencesource.microsoft.com/#System.Web/ModelBinding/DataAnnotationsModelMetadataProvider.cs,38). –  Mar 14 '17 at 20:02