DataType AutoCorrect Event
Summary
The DataType AutoCorrect event automatically transforms property values based on their data type. It provides reusable formatting rules that apply to all properties of a given data type — such as capitalizing proper nouns, trimming text, or formatting phone numbers.
When does it fire?
DataType AutoCorrect fires during the property set pipeline, after the read-only check and before property-level AutoCorrect:
Set property → ReadOnly → DataType AutoCorrect → Property AutoCorrect
→ DataType Validate → Property Validate → Dirty → Changed
Syntax
Data type auto-correct is defined in a business logic class that takes the data type's logic container:
[Logic]
public class MyDataTypeBL(MyDataType.Logic dataType)
{
[RegisterLogic]
public void AutoCorrect()
{
dataType.AutoCorrect()
.Transform(value => /* return corrected value */);
}
}
Fluent API
| Step | Method | Description |
|---|---|---|
| Required | .Transform(expression) |
The function that transforms and returns the corrected value |
Scenarios
1. Capitalizing the first letter of proper nouns
All ProperNoun properties (customer names, contact names, city names) should start with an uppercase letter.
[Logic]
public class ProperNounBL(DataTypes.ProperNoun.Logic dataType)
{
[RegisterLogic]
public void AutoCorrectCapitalization()
{
dataType.AutoCorrect()
.Transform(value =>
{
if (string.IsNullOrEmpty(value)) return value;
return char.ToUpper(value[0]) + value[1..];
});
}
}
This auto-correction applies everywhere [Property<DataTypes.ProperNoun>] is used — Contact.FirstName, Contact.LastName, Customer.FullName, etc.
2. Trimming whitespace from text fields
All generic Text properties should have leading and trailing whitespace removed.
[Logic]
public class TextBL(DataTypes.Text.Logic dataType)
{
[RegisterLogic]
public void AutoCorrectTrim()
{
dataType.AutoCorrect()
.Transform(value => value?.Trim());
}
}
3. Uppercasing ID codes
All IdText properties (customer IDs, product SKUs) should be stored in uppercase.
[Logic]
public class IdTextBL(DataTypes.IdText.Logic dataType)
{
[RegisterLogic]
public void AutoCorrectUppercase()
{
dataType.AutoCorrect()
.Transform(value => value?.ToUpperInvariant());
}
}
DataType AutoCorrect vs. Property AutoCorrect
| DataType AutoCorrect | Property AutoCorrect | |
|---|---|---|
| Scope | All properties of that data type | One specific property |
| Defined on | Data type logic class | Entity logic class |
| Use for | Universal formatting rules | Entity-specific transformations |
| Order | Runs first | Runs after data type auto-correct |
Notes
- DataType AutoCorrect runs before property-level AutoCorrect — both transformations are applied in sequence.
- AutoCorrect should be idempotent (applying it twice produces the same result).
- AutoCorrect should never reject values — use DataType Validate or Property Validate for rejection.
- Define custom data types when you need reusable auto-correct for a specific kind of data.