I have this API function:
public ResultEnum DoSomeAction(string a, string b, DateTime c, OtherEnum d,
string e, string f, out Guid code)
Use the structure, but instead of public fields, have public properties:
•Everybody (including FXCop & Jon Skeet) agree that exposing public fields are bad.
Jon and FXCop will be satisified because you are exposing properites not fields.
•Eric Lippert et al say relying on readonly fields for immutability is a lie.
Eric will be satisifed because using properties, you can ensure that the value is only set once.
private bool propC_set=false;
private date pC;
public date C {
get{
return pC;
}
set{
if (!propC_set) {
pC = value;
}
propC_set = true;
}
}
One semi-immutable object (value can be set but not changed). Works for value and Reference types.