using System; using System.Collections.Generic; using System.Linq; namespace FlexFramework.Excel { public abstract class TableMapperBase : MapperBase where T : TableMapperBase { protected readonly List excludes; protected int index; protected TableMapperBase(Type type) : base(type) { excludes = new List(); } public override void Extract() { var attribute = Attribute.GetCustomAttribute(type, typeof(TableAttribute)) as TableAttribute; if (attribute != null) { if (attribute.Ignore != null && attribute.Ignore.Length > 0) { Exclude(attribute.Ignore); } SafeMode = attribute.SafeMode; } base.Extract(); } /// /// Exclude target rows from being instantiated /// /// One-based row indices /// Mapper instance public T Exclude(params int[] rows) { if (rows == null || rows.Length == 0) { throw new ArgumentException("Rows must be specified"); } for (int i = 0; i < rows.Length; i++) { if (rows[i] < 1) { throw new ArgumentException("One-based row index must be greater than 0"); } rows[i]--; } excludes.AddRange(rows); return (T)this; } /// /// Include target rows to being instantiated /// /// One-based row indices /// Mapper instance public T Include(params int[] rows) { if (rows == null || rows.Length == 0) { throw new ArgumentException("Rows must be specified"); } for (int i = 0; i < rows.Length; i++) { if (rows[i] < 1) { throw new ArgumentException("One-based row index must be greater than 0"); } rows[i]--; } excludes.RemoveAll(i => rows.Contains(i)); return (T)this; } /// /// Include all rows to being instantiated /// /// Mapper instance public T IncludeAll() { excludes.Clear(); return (T)this; } } }