コード例 #1
0
        public virtual ValidationResult <string> GetHeaderWithValidation <T>(WorksheetMap <T> worksheetMap,
                                                                             MessageErrors messageErrors)
        {
            var expectedHeader = worksheetMap.GetFields().Select(s => s.Name).ToList();
            var header         = GetHeader();

            var validationResult = new ValidationResult <string>();

            if (header == null)
            {
                validationResult.AddError(new Error(messageErrors.NullHeaderErrorMessage(), StartRow, StartColumn));
            }

            foreach (var headerItem in header)
            {
                if (headerItem != messageErrors.HeaderFirstColumnWithErrors && !expectedHeader.Contains(headerItem))
                {
                    validationResult.AddError(new Error(messageErrors.InvalidItemHeader(headerItem), StartRow, header.IndexOf(headerItem)));
                }
                else
                {
                    validationResult.AddItem(headerItem);
                }
            }

            foreach (var expectedHeaderItem in expectedHeader)
            {
                if (!header.Contains(expectedHeaderItem))
                {
                    validationResult.AddError(new Error(messageErrors.MissingItemHeader(expectedHeaderItem), StartRow, StartColumn));
                }
            }

            return(validationResult);
        }
コード例 #2
0
 public WorksheetInterpreter(ValueSetter valueSetter,
                             WorksheetMap <T> worksheetMap,
                             MessageErrors messageErrors)
 => (this.valueSetter, this.worksheetMap, this.messageErrors)