Exemplo n.º 1
0
        /// <summary>
        /// Given a string element in the csv and target type
        /// Deserialize it into an object of the target type
        /// </summary>
        /// <param name="item"></param>
        /// <param name="typeInfo"></param>
        /// <param name="expectedItemType"></param>
        /// <returns></returns>
        public object DeserializeItem(string item, string typeInfo, string csvFieldName, Type expectedItemType, Type dataEntryType)
        {
            IDataType dataType = dataTypeFactory.GetDataType(typeInfo, csvFieldName);

            dataType.deserializeExtraInfo = new DataTypeDeserializeExtraInfo(csvFieldName, dataEntryType);

            try
            {
                return(dataType.Deserialize(Helper.CorrectDataItemString(item), expectedItemType));
            }
            catch (CSVParseException e)
            {
                throw new CSVParseException(e.ToString(), currentRow, currentColumn);
            }
            catch (Exception e)
            {
                throw new CSVParseException("Unknown exception: " + e.ToString(), currentRow, currentColumn);
            }
        }
Exemplo n.º 2
0
        public object Deserialize(string rawItem, Type expectedType)
        {
            InitReflectionTypeInfo(expectedType);

            // create array of baseType
            object array = Activator.CreateInstance(expectedType);

            if (rawItem == CSVConstant.EMPTY_ITEM)
            {
                return(array);
            }

            string[] rawElements = rawItem.Split(arrayDelimeter);
            for (int i = 0; i < rawElements.Length; i++)
            {
                object element = baseDataType.Deserialize(rawElements[i], baseSystemType);
                AddToArray(array, element);
            }

            return(array);
        }
Exemplo n.º 3
0
 public virtual object Deserialize(string rawItem, Type expectedType)
 {
     return(refType.Deserialize(rawItem, expectedType));
 }