Exemplo n.º 1
0
        private ExtractedInfo BasicExtractString(LineInfo line)
        {
            if (IsLast && !IsArray)
            {
                var sepPos = line.IndexOf(mSeparator);

                if (sepPos == -1)
                {
                    return(new ExtractedInfo(line));
                }

                // Now check for one extra separator
                var msg = string.Format("Delimiter '{0}' found after the last field '{1}' (the file is wrong or you need to add a field to the record class)", mSeparator, this.FieldInfo.Name, line.mReader.LineNumber);

                throw new BadUsageException(line.mReader.LineNumber, line.mCurrentPos, msg);
            }
            else
            {
                int sepPos;

                sepPos = line.IndexOf(mSeparator);

                if (sepPos == -1)
                {
                    if (IsLast && IsArray)
                    {
                        return(new ExtractedInfo(line));
                    }

                    if (NextIsOptional == false)
                    {
                        string msg;

                        if (IsFirst && line.EmptyFromPos())
                        {
                            msg = string.Format("The line {0} is empty. Maybe you need to use the attribute [IgnoreEmptyLines] in your record class.", line.mReader.LineNumber);
                        }
                        else
                        {
                            msg = string.Format("Delimiter '{0}' not found after field '{1}' (the record has less fields, the delimiter is wrong or the next field must be marked as optional).", mSeparator, this.FieldInfo.Name, line.mReader.LineNumber);
                        }

                        throw new FileHelpersException(line.mReader.LineNumber, line.mCurrentPos, msg);
                    }
                    else
                    {
                        sepPos = line.mLineStr.Length;
                    }
                }

                return(new ExtractedInfo(line, sepPos));
            }
        }
Exemplo n.º 2
0
        private ExtractedInfo BasicExtractString(LineInfo line)
        {
            ExtractedInfo res;

            if (mIsLast)
            {
                res = new ExtractedInfo(line);
            }
            else
            {
                int sepPos;

                sepPos = line.IndexOf(mSeparator);

                if (sepPos == -1)
                {
                    if (this.mNextIsOptional == false)
                    {
                        string msg = null;

                        if (mIsFirst && line.EmptyFromPos())
                        {
                            msg = "The line " + line.mReader.LineNumber.ToString() + " is empty. Maybe you need to use the attribute [IgnoreEmptyLines] in your record class.";
                        }
                        else
                        {
                            msg = "The delimiter '" + this.mSeparator + "' can´t be found after the field '" + this.mFieldInfo.Name + "' at line " + line.mReader.LineNumber.ToString() + " (the record has less fields, the delimiter is wrong or the next field must be marked as optional).";
                        }

                        throw new FileHelpersException(msg);
                    }
                    else
                    {
                        sepPos = line.mLine.Length - 1;
                    }
                }

                res = new ExtractedInfo(line, sepPos);
            }
            return(res);
        }
Exemplo n.º 3
0
        private ExtractedInfo BasicExtractString(LineInfo line)
        {
            if (IsLast && ! IsArray)
                return new ExtractedInfo(line);
            else
            {
                int sepPos;

                sepPos = line.IndexOf(mSeparator);

                if (sepPos == -1)
                {
                    if (IsLast && IsArray)
                        return new ExtractedInfo(line);

                    if (NextIsOptional == false)
                    {
                        string msg;

                        if (IsFirst && line.EmptyFromPos())
                            msg = string.Format("The line {0} is empty. Maybe you need to use the attribute [IgnoreEmptyLines] in your record class.", line.mReader.LineNumber);
                        else
                            msg = string.Format("Delimiter '{0}' not found after field '{1}' (the record has less fields, the delimiter is wrong or the next field must be marked as optional).", mSeparator, this.FieldInfo.Name, line.mReader.LineNumber);

                        throw new FileHelpersException(line.mReader.LineNumber, line.mCurrentPos, msg);

                    }
                    else
                        sepPos = line.mLine.Length;
                }

                return new ExtractedInfo(line, sepPos);
            }
        }
Exemplo n.º 4
0
		private ExtractedInfo BasicExtractString(LineInfo line)
		{
			ExtractedInfo res;
			
			if (mIsLast)
				res = new ExtractedInfo(line);
			else
			{
				int sepPos;

				sepPos = line.IndexOf(mSeparator);

				if (sepPos == -1)
				{
					if (this.mNextIsOptional == false)
					{
						string msg = null;

						if (mIsFirst && line.EmptyFromPos())
							msg = "The line " + line.mReader.LineNumber.ToString() + " is empty. Maybe you need to use the attribute [IgnoreEmptyLines] in your record class.";
						else
							msg = "The delimiter '" + this.mSeparator + "' can´t be found after the field '" + this.mFieldInfo.Name + "' at line " + line.mReader.LineNumber.ToString() + " (the record has less fields, the delimiter is wrong or the next field must be marked as optional).";

						throw new FileHelpersException(msg);

					}
					else
						sepPos = line.mLine.Length - 1;
				}

				res = new ExtractedInfo(line, sepPos);
			}
			return res;
		}