Exemple #1
0
        /// <summary>
        /// Create using supplied settings.
        /// </summary>
        /// <param name="contentOrFilePath"></param>
        /// <param name="isFilePath"></param>
        /// <param name="settings"></param>
        /// <param name="autoLoad"></param>
        public CsvDoc(string contentOrFilePath, bool isFilePath, CsvConfig settings, bool autoLoad)
        {
            // Store settings
            _isFileBased = isFilePath;

            if (isFilePath && !File.Exists(contentOrFilePath))
            {
                throw new IOException("Csv file : " + contentOrFilePath + " does not exist.");
            }

            _content  = isFilePath ? File.ReadAllText(contentOrFilePath) : contentOrFilePath;
            _filePath = isFilePath ? contentOrFilePath : "";
            _settings = settings;

            var lexListSettings = new LexListSettings()
            {
                MultipleRecordsUsingNewLine = true, Delimeter = settings.Separator
            };

            // If the separator is the tab character, do not consider the tab as a whitespace character.
            if (settings.Separator == '\t')
            {
                lexListSettings = new LexListSettings()
                {
                    MultipleRecordsUsingNewLine = true, Delimeter = settings.Separator, WhiteSpaceChars = new char[] { ' ' }
                }
            }
            ;

            _parser = new LexList(lexListSettings);
            if (autoLoad)
            {
                ParseDict();
            }
        }
        /// <summary>
        /// Create using supplied settings.
        /// </summary>
        /// <param name="contentOfFilePath"></param>
        /// <param name="isFilePath"></param>
        /// <param name="settings"></param>
        public CsvDoc(string contentOrFilePath, bool isFilePath, CsvConfig settings, bool autoLoad)
        {
            // Store settings
            _isFileBased = isFilePath;

            if (isFilePath && !File.Exists(contentOrFilePath))
            {
                throw new IOException("Csv file : " + contentOrFilePath + " does not exist.");
            }

            _content  = isFilePath ? File.ReadAllText(contentOrFilePath) : contentOrFilePath;
            _filePath = isFilePath ? contentOrFilePath : "";
            _settings = settings;

            var lexListSettings = new LexListSettings()
            {
                MultipleRecordsUsingNewLine = true, Delimeter = settings.Separator
            };

            _parser = new LexList(lexListSettings);
            if (autoLoad)
            {
                ParseDict();
            }
        }
        /// <summary>
        /// Create using supplied settings.
        /// </summary>
        /// <param name="contentOfFilePath"></param>
        /// <param name="isFilePath"></param>
        /// <param name="settings"></param>
        public CsvDocument(string contentOrFilePath, bool isFilePath, CsvSettings settings)
        {
            _content = contentOrFilePath;

            if (isFilePath)
            {
                _filePath    = contentOrFilePath;
                _content     = File.ReadAllText(contentOrFilePath);
                _isFileBased = true;
            }
            LexListSettings lexListSettings = new LexListSettings();

            lexListSettings.MultipleRecordsUsingNewLine = true;
            _parser = new LexList(lexListSettings);
        }
        /// <summary>
        /// Create using supplied settings.
        /// </summary>
        /// <param name="contentOfFilePath"></param>
        /// <param name="isFilePath"></param>
        /// <param name="settings"></param>
        public CsvDoc(string contentOrFilePath, bool isFilePath, CsvConfig settings, bool autoLoad)
        {
            // Store settings
            _isFileBased = isFilePath;
            _content     = isFilePath ? File.ReadAllText(contentOrFilePath) : contentOrFilePath;
            _filePath    = isFilePath ? contentOrFilePath : "";
            _settings    = settings;

            LexListSettings lexListSettings = new LexListSettings()
            {
                MultipleRecordsUsingNewLine = true
            };

            _parser = new LexList(lexListSettings);
            if (autoLoad)
            {
                ParseDict();
            }
        }