本文整理汇总了C#中FileHelpers.LineInfo.EmptyFromPos方法的典型用法代码示例。如果您正苦于以下问题:C# LineInfo.EmptyFromPos方法的具体用法?C# LineInfo.EmptyFromPos怎么用?C# LineInfo.EmptyFromPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelpers.LineInfo
的用法示例。
在下文中一共展示了LineInfo.EmptyFromPos方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractFieldValue
/// <summary>
/// Get the data out of the records
/// </summary>
/// <param name="line">Line handler containing text</param>
/// <returns></returns>
internal object ExtractFieldValue(LineInfo line)
{
//-> extract only what I need
if (InNewLine) {
// Any trailing characters, terminate
if (line.EmptyFromPos() == false) {
throw new BadUsageException(line,
"Text '" + line.CurrentString +
"' found before the new line of the field: " + FieldInfo.Name +
" (this is not allowed when you use [FieldInNewLine])");
}
line.ReLoad(line.mReader.ReadNextLine());
if (line.mLineStr == null) {
throw new BadUsageException(line,
"End of stream found parsing the field " + FieldInfo.Name +
". Please check the class record.");
}
}
if (IsArray == false) {
ExtractedInfo info = ExtractFieldString(line);
if (info.mCustomExtractedString == null)
line.mCurrentPos = info.ExtractedTo + 1;
line.mCurrentPos += CharsToDiscard; //total;
if (Discarded)
return GetDiscardedNullValue();
else
return AssignFromString(info, line).Value;
}
else {
if (ArrayMinLength <= 0)
ArrayMinLength = 0;
int i = 0;
var res = new ArrayList(Math.Max(ArrayMinLength, 10));
while (line.mCurrentPos - CharsToDiscard < line.mLineStr.Length &&
i < ArrayMaxLength) {
ExtractedInfo info = ExtractFieldString(line);
if (info.mCustomExtractedString == null)
line.mCurrentPos = info.ExtractedTo + 1;
line.mCurrentPos += CharsToDiscard;
try {
var value = AssignFromString(info, line);
if (value.NullValueUsed &&
i == 0 &&
line.IsEOL())
break;
res.Add(value.Value);
}
catch (NullValueNotFoundException) {
if (i == 0)
break;
else
throw;
}
i++;
}
if (res.Count < ArrayMinLength) {
throw new InvalidOperationException(
string.Format(
"Line: {0} Column: {1} Field: {2}. The array has only {3} values, less than the minimum length of {4}",
line.mReader.LineNumber.ToString(),
line.mCurrentPos.ToString(),
FieldInfo.Name,
res.Count,
ArrayMinLength));
}
else if (IsLast && line.IsEOL() == false) {
throw new InvalidOperationException(
string.Format(
"Line: {0} Column: {1} Field: {2}. The array has more values than the maximum length of {3}",
line.mReader.LineNumber,
line.mCurrentPos,
FieldInfo.Name,
ArrayMaxLength));
}
// TODO: is there a reason we go through all the array processing then discard it
if (Discarded)
return null;
else
return res.ToArray(ArrayType);
}
//.........这里部分代码省略.........
示例2: BasicExtractString
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);
}
}
示例3: BasicExtractString
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;
}
示例4: ExtractValue
// object[] values, int index, ForwardReader reader
internal object ExtractValue(LineInfo line)
{
//-> extract only what I need
if (this.mInNewLine == true)
{
if (line.EmptyFromPos() == false)
throw new BadUsageException("Text '" + line.CurrentString +
"' found before the new line of the field: " + mFieldInfo.Name +
" (this is not allowed when you use [FieldInNewLine])");
line.ReLoad(line.mReader.ReadNextLine());
if (line.mLineStr == null)
throw new BadUsageException("End of stream found parsing the field " + mFieldInfo.Name +
". Please check the class record.");
}
ExtractedInfo info = ExtractFieldString(line);
if (info.mCustomExtractedString == null)
line.mCurrentPos = info.ExtractedTo + 1;
line.mCurrentPos += mCharsToDiscard; //total;
return AssignFromString(info, line);
//-> discard the part that I use
//TODO: Uncoment this for Quoted Handling
// if (info.NewRestOfLine != null)
// {
// if (info.NewRestOfLine.Length < CharsToDiscard())
// return info.NewRestOfLine;
// else
// return info.NewRestOfLine.Substring(CharsToDiscard());
// }
// else
// {
// int total;
// if (info.CharsRemoved >= line.mLine.Length)
// total = line.mLine.Length;
// else
// total = info.CharsRemoved + CharsToDiscard();
//return buffer.Substring(total);
// }
}
示例5: ExtractFieldValue
internal object ExtractFieldValue(LineInfo line)
{
//-> extract only what I need
if (InNewLine)
{
if (line.EmptyFromPos() == false)
throw new BadUsageException(line, "Text '" + line.CurrentString +
"' found before the new line of the field: " + FieldInfo.Name +
" (this is not allowed when you use [FieldInNewLine])");
line.ReLoad(line.mReader.ReadNextLine());
if (line.mLineStr == null)
throw new BadUsageException(line, "End of stream found parsing the field " + FieldInfo.Name +
". Please check the class record.");
}
if (IsArray == false)
{
ExtractedInfo info = ExtractFieldString(line);
if (info.mCustomExtractedString == null)
line.mCurrentPos = info.ExtractedTo + 1;
line.mCurrentPos += CharsToDiscard; //total;
return AssignFromString(info, line);
}
else
{
if (ArrayMinLength <= 0)
ArrayMinLength = 0;
int i = 0;
var res = new ArrayList(Math.Max(ArrayMinLength, 10));
while (line.mCurrentPos - CharsToDiscard < line.mLine.Length && i < ArrayMaxLength)
{
ExtractedInfo info = ExtractFieldString(line);
if (info.mCustomExtractedString == null)
line.mCurrentPos = info.ExtractedTo + 1;
line.mCurrentPos += CharsToDiscard;
res.Add(AssignFromString(info, line));
i++;
}
if (res.Count < ArrayMinLength)
throw new InvalidOperationException(string.Format("Line: {0} Column: {1} Field: {2}. The array has only {3} values, less than the minimum length of {4}", line.mReader.LineNumber.ToString(), line.mCurrentPos.ToString(), FieldInfo.Name, res.Count, ArrayMinLength));
else if (IsLast && line.IsEOL() == false)
throw new InvalidOperationException(string.Format("Line: {0} Column: {1} Field: {2}. The array has more values than the maximum length of {3}", line.mReader.LineNumber, line.mCurrentPos, FieldInfo.Name, ArrayMaxLength));
return res.ToArray(ArrayType);
}
}