Properties should not be write only
.NET Framework 2.0
| TypeName | PropertiesShouldNotBeWriteOnly |
| CheckId | CA1044 |
| Category | Microsoft.Design |
| Breaking Change | Breaking |
Get accessors provide read access to a property and set accessors provide write access. While it is acceptable and often necessary to have a read-only property, the design guidelines prohibit using write-only properties because allowing a user to set a value, and then preventing the user from viewing the value does not provide any security. Also, without read access, the state of shared objects cannot be viewed, which limits their usefulness.
In the following example, BadClassWithWriteOnlyProperty is a type with a write-only property. GoodClassWithReadWriteProperty contains the corrected code.
using System; namespace DesignLibrary { public class BadClassWithWriteOnlyProperty { string someName; // Violates rule PropertiesShouldNotBeWriteOnly. public string Name { set { someName = value; } } } public class GoodClassWithReadWriteProperty { string someName; public string Name { get { return someName; } set { someName = value; } } } }