public class MyColumnRow {
public int Id { get; set; }
[ValidateColumn(ValidationMethod = ValidationMethod.IsNotNull)]
[ValidateColumn(ValidationMethod = ValidationMethod.IsNumberBetween, Parameter1 = 1, Parameter2 = 10)]
public int? Value1 { get; set; }
[ValidateColumn(ValidationMethod = ValidationMethod.IsNotZero)]
public string Value2 { get; set; }
[ValidateColumn(ValidationMethod = ValidationMethod.IsPositive)]
public decimal? Value3 { get; set; }
[ValidateColumn(ValidationMethod = ValidationMethod.IsEquals, Parameter1 = 3.34)]
public double? Value4 { get; set; }
[ValidateColumn(ValidationMethod = ValidationMethod.IsNumeric)]
public string ValueS { get; set; }
public ValidationResult ConversionResult { get; set; }
}
var source = new MemorySource<MyColumnRow>();
// All valid
source.DataAsList.Add(new MyColumnRow() { Id = 1, Value1 = 5, Value2 = "1", Value3 = 10.5m, Value4 = 3.34, ValueS = "123" });
// Multiple errors
source.DataAsList.Add(new MyColumnRow() { Id = 2, Value1 = 11, Value2 = "0", Value3 = -5.0m, Value4 = 2.5, ValueS = "abc" });
// Valid except Value3 is null
source.DataAsList.Add(new MyColumnRow() { Id = 3, Value1 = 7, Value2 = "10", Value3 = null, Value4 = 3.34, ValueS = "44" });
// Missing Value1 and Value4
source.DataAsList.Add(new MyColumnRow() { Id = 4, Value1 = null, Value2 = "5", Value3 = 15.5m, Value4 = null, ValueS = "100" });
var trans = new RowValidation<MyColumnRow>();
var valid = new MemoryDestination<MyColumnRow>();
var invalid = new MemoryDestination<MyColumnRow>();
source.LinkTo(trans);
trans.LinkTo(valid);
trans.LinkInvalidTo(invalid);
Network.Execute(trans);
Console.WriteLine("Valid Rows:");
foreach (var row in valid.Data) {
Console.WriteLine($"Id: {row.Id}, Value1: {row.Value1}, Value2: {row.Value2}, Value3: {row.Value3}, Value4: {row.Value4}, ValueS: {row.ValueS}");
}
Console.WriteLine("Invalid Rows:");
foreach (var row in invalid.Data) {
Console.WriteLine($"Id: {row.Id}, Value1: {row.Value1}, Value2: {row.Value2}, Value3: {row.Value3}, Value4: {row.Value4}, ValueS: {row.ValueS}");
if (row.ConversionResult != null && row.ConversionResult.Errors != null) {
Console.WriteLine("Errors:");
foreach (var error in row.ConversionResult.Errors) {
Console.WriteLine($" - {error.Reason} (Value: {error.Value})");
}
}
}
/* Output:
Valid Rows:
Id: 1, Value1: 5, Value2: 1, Value3: 10.5, Value4: 3.34, ValueS: 123
Invalid Rows:
Id: 2, Value1: 11, Value2: 0, Value3: -5.0, Value4: 2.5, ValueS: abc
Errors:
- Number is not between '1' and '10', but expected it to be. (Value: 11)
- Value is zero, but expected value to be not zero. (Value: 0)
- Value is not positive, but expected value to be positive. (Value: -5.0)
- Value is not equal '3.34', but expected value to be equal. (Value: 2.5)
- Value is not numeric, but expected value to be numeric. (Value: abc)
Id: 3, Value1: 7, Value2: 10, Value3: , Value4: 3.34, ValueS: 44
Errors:
- Value is not positive, but expected value to be positive. (Value: )
Id: 4, Value1: , Value2: 5, Value3: 15.5, Value4: , ValueS: 100
Errors:
- Value is null, but expected value to be not null. (Value: )
- Number is not between '1' and '10', but expected it to be. (Value: )
- Value is not equal '3.34', but expected value to be equal. (Value: )
*/