Esempio n. 1
0
        /// <summary>
        /// Parse the csv text.
        /// </summary>
        /// <param name="text">The csv formatted text string.</param>
        /// <param name="hasHeaders">Whether or not the csv text has headers.</param>
        /// <param name="isReadOnly">Whether or not to make the parsed doc readonly.</param>
        /// <param name="delimeter">Dellimeter to use for separate values.</param>
        /// <returns>A CsvDoc</returns>
        public static CsvDoc Load(string text, bool hasHeaders, bool isReadOnly, string delimeter)
        {
            var settings = new CsvConfig()
            {
                ContainsHeaders = hasHeaders, Separator = delimeter, IsReadOnly = isReadOnly
            };
            CsvDoc doc = new CsvDoc(text, true, settings, true);

            return(doc);
        }
Esempio n. 2
0
        /// <summary>
        /// Whether or not the csv file can be loaded.
        /// </summary>
        /// <param name="text">The csv formatted text string.</param>
        /// <param name="hasHeaders">Whether or not the csv text has headers.</param>
        /// <param name="isReadOnly">Whether or not to make the parsed doc readonly.</param>
        /// <param name="parseMap">Whether or not to parse the data as a list of dictionaries.</param>
        /// <returns>A CsvDoc</returns>
        public static BoolMessageItem <CsvDoc> CanLoad(string text, bool hasHeaders, bool isReadOnly, string delimeter)
        {
            CsvDoc doc     = null;
            bool   loaded  = true;
            string message = string.Empty;

            ExecuteHelper.TryCatch(() => doc = Load(text, hasHeaders, isReadOnly, delimeter), (ex) =>
            {
                loaded  = false;
                message = ex.Message;
            });
            return(new BoolMessageItem <CsvDoc>(doc, loaded, message));
        }