-
Notifications
You must be signed in to change notification settings - Fork 2
3. Attribute Configuration
Another way to map configuration to model is by adding DataAtributes to your model:
[SheetToObjectConfig(sheetHasHeaders:true)]
public class ToModel
{
[MappingByHeader("StringValue")]
[IsRequired]
[Regex(@"/^[a-z]+[0-9_\/\s,.-]+$", true)]
public string StringProperty { get; set; }
}
At the moment there is only one class attribute: SheetToObjectConfig. With this attribute u can set the default settings to map this model.
The following default validation attributes are available as attributes; [IsRequired] [Regex]
The model attributes can be overwritten by configuring a config for the model on the used SheetMapper
There are multiple ways to map a column in the datasource to the model property
Use the .WithColumnIndex or [MappingByIndex] attribute to map the property based on Index. The index is 0-based
Use the .WithColumnLetter() or [MappingByLetter] attribute to map the attribute base on "Excel-style" column naming. column "A" is the first column and "D" the fourth.
When the datasource contains a first row with headers it's possible to map by name. Use the .WithHeader() or [MappingByHeader] to map by the name that is used on the first row
It's also possible to automap the properties based on their name without configuring anything. A header row is required for this feature, which name needs to match the name of the property you need that column to be mapped to.
When u don't want the property to be mapped use the [IgnorePropertyMapping]
attribute on the property.
For more information, check out the tests: https://github.com/josdeweger/SheetToObjects/blob/dev/src/SheetToObjects.Specs