예제 #1
0
        public object MapValue(Type type, object rawValue)
        {
            if (type == typeof(string))
            {
                return(rawValue.ToString());
            }

            if (type == typeof(short))
            {
                return(Convert.ToInt16(rawValue));
            }

            if (type == typeof(int))
            {
                return(Convert.ToInt32(rawValue));
            }

            if (type == typeof(long))
            {
                return(Convert.ToInt64(rawValue));
            }

            if (type == typeof(double))
            {
                return(Convert.ToDouble(rawValue));
            }

            if (type == typeof(decimal))
            {
                return(Convert.ToDecimal(rawValue));
            }

            throw ExcelWorksheetMapperException.UnsupportedColumnType(typeName: type.FullName);
        }
예제 #2
0
        public void AddColumn(
            int columnIndex,
            string columnName,
            Type columnType,
            out int addedIndex,
            string parentName = null)
        {
            columnIndex = parentName == null
                ? columnIndex
                : GetColumnIndexWithOffset(parentName, columnIndex);
            if (_columns.ContainsKey(columnIndex))
            {
                throw ExcelWorksheetMapperException.ColumnIndexAlreadyExists(
                          addedColumn: columnName,
                          columnIndex: columnIndex,
                          alreadyContainedName: _columns[columnIndex].FullName);
            }

            columnName = parentName == null
                ? columnName
                : IncludeName(parentName, columnName);

            _columns[columnIndex] = new Column(columnIndex, columnName, columnType);

            addedIndex = columnIndex;
        }
예제 #3
0
        public ConverterAttribute(Type converterType)
        {
            if (converterType == null)
            {
                throw new ArgumentNullException(nameof(converterType));
            }

            if (!typeof(IConverter).IsAssignableFrom(converterType))
            {
                throw ExcelWorksheetMapperException.InvalidConverterType(converterType.FullName);
            }

            ConverterType = converterType;
        }