clint wrote:
Walaa wrote:
Option one:
Add a partial class file add a new property that sets the original property.
In your code set use the new property instead of the original one.
I suppose that would work if the other programmers actually see the new property and use it.
Fair enough.
Walaa wrote:
Option two:
Use a Validator class.
You can validate and modify the value of the field when the field is set (ValidateFieldValue)
Or you can Validate or modify the value when saving (ValidateEntityBeforeSave)
For more details please check Validation
I like this idea better. I don't have to rely on the programmer to do anything special when setting a property like he would with your first idea. I was going to make a validator class anyways, so it's not like I'm doing a lot of extra work. However, it seems odd to have validation code changing the data.
It indeed works. Yes, it's kind of odd putting it into a validation code, but it also makes sense.
Additional to what Walaa suggested, you have a third option: PreProcess the value to be set. This can be done in a partial class as well:
using SD.LLBLGen.Pro.ORMSupportClasses;
namespace NW.LLBL.MSSQL.Adapter.v31.EntityClasses
{
public partial class CustomerEntity
{
protected override void PreProcessValueToSet(IEntityField2 fieldToSet, ref object valueToSet)
{
base.PreProcessValueToSet(fieldToSet, ref valueToSet);
// right align the value with a 40 pad
if (fieldToSet.FieldIndex == ((int)CustomerFieldIndex.CompanyName))
{
valueToSet = ((string)valueToSet).PadLeft(40);
}
}
}
}
This is a test of that:
[TestMethod]
public void CompanyNameShouldBeLeftPadded()
{
var customer = new CustomerEntity();
customer.CompanyName = "ABC";
Assert.AreEqual(40, customer.CompanyName.Length);
Assert.AreEqual("ABC".PadLeft(40), customer.CompanyName);
}