• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# FileHelpers.LineInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中FileHelpers.LineInfo的典型用法代码示例。如果您正苦于以下问题:C# LineInfo类的具体用法?C# LineInfo怎么用?C# LineInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LineInfo类属于FileHelpers命名空间,在下文中一共展示了LineInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: StringToRecord

        /// <summary>
        /// Extract fields from record and assign values to the object
        /// </summary>
        /// <param name="record">Object to assign to</param>
        /// <param name="line">Line of data</param>
        /// <param name="values">Array of values extracted</param>
        /// <returns>true if we processed the line and updated object</returns>
        public bool StringToRecord(object record, LineInfo line, object[] values)
        {
            if (MustIgnoreLine(line.mLineStr))
                return false;

            for (int i = 0; i < RecordInfo.FieldCount; i++)
                values[i] = RecordInfo.Fields[i].ExtractFieldValue(line);

            try {
                // Assign all values via dynamic method that
                AssignHandler(record, values);
                return true;
            }
            catch (InvalidCastException ex) {
                // Occurs when a custom converter returns an invalid value for the field.
                for (int i = 0; i < RecordInfo.FieldCount; i++) {
                    if (values[i] != null &&
                        !RecordInfo.Fields[i].FieldTypeInternal.IsInstanceOfType(values[i])) {
                        throw new ConvertException(null,
                            RecordInfo.Fields[i].FieldTypeInternal,
                            RecordInfo.Fields[i].FieldInfo.Name,
                            line.mReader.LineNumber,
                            -1,
                            Messages.Errors.WrongConverter
                                .FieldName(RecordInfo.Fields[i].FieldInfo.Name)
                                .ConverterReturnedType(values[i].GetType().Name)
                                .FieldType(RecordInfo.Fields[i].FieldInfo.FieldType.Name)
                                .Text
                            ,
                            ex);
                    }
                }
                throw;
            }
        }
开发者ID:calebillman,项目名称:FileHelpers,代码行数:42,代码来源:RecordOperations.cs


示例2: ExtractFieldString

		protected override ExtractedInfo ExtractFieldString(LineInfo line)
		{
			if (mIsOptional && line.IsEOL() )
				return ExtractedInfo.Empty;


			if (mQuoteChar == '\0')
				return BasicExtractString(line);
			else
			{
				//TODO: UnComment and Fix

				if (mTrimMode == TrimMode.Both || mTrimMode == TrimMode.Left)
				{

					//int pos = line.mCurrentPos;
					line.TrimStart(mTrimChars);
//					from2 = from.TrimStart(mTrimChars);
					//res.CharsRemoved = line.mCurrentPos - pos;
				}

				string quotedStr = mQuoteChar.ToString();
				if (line.StartsWith(quotedStr))
				{

//					ExtractedInfo res = null;
//					res = new ExtractedInfo(line, line.mCurrentPos);

					return StringHelper.ExtractQuotedString(line, mQuoteChar, mQuoteMultiline == MultilineMode.AllowForBoth || mQuoteMultiline == MultilineMode.AllowForRead);
//					if (mQuoteMultiline == MultilineMode.AllowForBoth || mQuoteMultiline == MultilineMode.AllowForRead)
//					{
//
//						//res.ExtractedString = ei.ExtractedString;
//						//res.CharsRemoved += ei.CharsRemoved;
//						//res.ExtraLines = ei.ExtraLines;
//						//res.NewRestOfLine = ei.NewRestOfLine;
//					}
//					else
//					{
//						return StringHelper.ExtractQuotedString(from2, mQuoteChar, out index);
//						//res.CharsRemoved += index;
//					}

				//	return res;

				}
				else
				{
					if (mQuoteMode == QuoteMode.OptionalForBoth || mQuoteMode == QuoteMode.OptionalForRead)
						return BasicExtractString(line);
					else if (line.StartsWithTrim(quotedStr))
						throw new BadUsageException("The field '" + this.mFieldInfo.Name + "' has spaces before the QuotedChar at line "+ line.mReader.LineNumber.ToString() + ". Use the TrimAttribute to by pass this error. Field String: " + line.CurrentString);
					else
						throw new BadUsageException("The field '" + this.mFieldInfo.Name + "' not begin with the QuotedChar at line "+ line.mReader.LineNumber.ToString() + ". You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field.. Field String: " + line.CurrentString);
				}

			}


		}
开发者ID:pjeconde,项目名称:CedForecast,代码行数:60,代码来源:DelimitedField.cs


示例3: ExtractedInfo

 /// <summary>
 /// Extract the rest of the line into my variable
 /// </summary>
 /// <param name="line"></param>
 public ExtractedInfo(LineInfo line)
 {
     mLine = line;
     ExtractedFrom = line.mCurrentPos;
     ExtractedTo = line.mLineStr.Length - 1;
     mCustomExtractedString = null;
 }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:11,代码来源:ExtractInfo.cs


示例4: ExtractFieldString

        internal override ExtractedInfo ExtractFieldString(LineInfo line)
        {
            if (mIsOptional && line.IsEOL() )
                return ExtractedInfo.Empty;

            if (mQuoteChar == '\0')
                return BasicExtractString(line);
            else
            {
                if (mTrimMode == TrimMode.Both || mTrimMode == TrimMode.Left)
                {
                    line.TrimStart(mTrimChars);
                }

                string quotedStr = mQuoteChar.ToString();
                if (line.StartsWith(quotedStr))
                {
                    return StringHelper.ExtractQuotedString(line, mQuoteChar, mQuoteMultiline == MultilineMode.AllowForBoth || mQuoteMultiline == MultilineMode.AllowForRead);
                }
                else
                {
                    if (mQuoteMode == QuoteMode.OptionalForBoth || mQuoteMode == QuoteMode.OptionalForRead)
                        return BasicExtractString(line);
                    else if (line.StartsWithTrim(quotedStr))
                        throw new BadUsageException(string.Format("The field '{0}' has spaces before the QuotedChar at line {1}. Use the TrimAttribute to by pass this error. Field String: {2}", mFieldInfo.Name, line.mReader.LineNumber, line.CurrentString));
                    else
                        throw new BadUsageException(string.Format("The field '{0}' not begin with the QuotedChar at line {1}. You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field.. Field String: {2}", mFieldInfo.Name, line.mReader.LineNumber, line.CurrentString));
                }

            }
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:31,代码来源:DelimitedField.cs


示例5: ExtractFieldString

        internal override ExtractedInfo ExtractFieldString(LineInfo line)
        {
            if (line.CurrentLength == 0)
            {
                if (mIsOptional)
                    return ExtractedInfo.Empty;
                else
                    throw new BadUsageException("End Of Line found processing the field: " + mFieldInfo.Name + " at line "+ line.mReader.LineNumber.ToString() + ". (You need to mark it as [FieldOptional] if you want to avoid this exception)");
            }

            ExtractedInfo res;

            if (line.CurrentLength < this.mFieldLength)
                if (mFixedMode == FixedMode.AllowLessChars ||
                    mFixedMode == FixedMode.AllowVariableLength)
                    res = new ExtractedInfo(line);
                else
                    throw new BadUsageException("The string '" + line.CurrentString + "' (length " + line.CurrentLength.ToString() + ") at line "+ line.mReader.LineNumber.ToString() + " has less chars than the defined for " + mFieldInfo.Name + " (" + mFieldLength.ToString() + "). You can use the [FixedLengthRecord(FixedMode.AllowLessChars)] to avoid this problem.");
            else if (line.CurrentLength > mFieldLength  &&
                        mIsArray == false &&
                        mIsLast &&
                        mFixedMode != FixedMode.AllowMoreChars &&
                        mFixedMode != FixedMode.AllowVariableLength)
                throw new BadUsageException("The string '" + line.CurrentString + "' (length " + line.CurrentLength.ToString() + ") at line "+ line.mReader.LineNumber.ToString() + " has more chars than the defined for the last field " + mFieldInfo.Name + " (" + mFieldLength.ToString() + ").You can use the [FixedLengthRecord(FixedMode.AllowMoreChars)] to avoid this problem.");
            else
                res = new ExtractedInfo(line, line.mCurrentPos + mFieldLength);

            return res;
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:29,代码来源:FixedLengthField.cs


示例6: ExtractedInfo

		public ExtractedInfo(LineInfo line, int extractTo)
		{
			mLine = line;
			ExtractedFrom = line.mCurrentPos;
			ExtractedTo = extractTo - 1;
			//CharsRemoved = ExtractedTo - ExtractedFrom + 1;
			//ExtraLines = 0;
		//	NewRestOfLine = null;
		}
开发者ID:pjeconde,项目名称:CedForecast,代码行数:9,代码来源:ExtractInfo.cs


示例7: ExtractFieldString

        /// <summary>
        /// Extract the field from the delimited file, removing separators and quotes
        /// and any duplicate quotes within the record
        /// </summary>
        /// <param name="line">line containing record input</param>
        /// <returns>Extract information</returns>
        internal override ExtractedInfo ExtractFieldString(LineInfo line)
        {
            if (IsOptional && line.IsEOL())
                return ExtractedInfo.Empty;

            if (QuoteChar == '\0')
                return BasicExtractString(line);
            else {
                if (TrimMode == TrimMode.Both ||
                    TrimMode == TrimMode.Left)
                    line.TrimStart(TrimChars);

                string quotedStr = QuoteChar.ToString();
                if (line.StartsWith(quotedStr)) {
                    var res = StringHelper.ExtractQuotedString(line,
                        QuoteChar,
                        QuoteMultiline == MultilineMode.AllowForBoth || QuoteMultiline == MultilineMode.AllowForRead);

                    if (TrimMode == TrimMode.Both ||
                        TrimMode == TrimMode.Right)
                        line.TrimStart(TrimChars);

                    if (!IsLast &&
                        !line.StartsWith(Separator) &&
                        !line.IsEOL()) {
                        throw new BadUsageException(line,
                            "The field " + this.FieldInfo.Name + " is quoted but the quoted char: " + quotedStr +
                            " not is just before the separator (You can use [FieldTrim] to avoid this error)");
                    }
                    return res;
                }
                else {
                    if (QuoteMode == QuoteMode.OptionalForBoth ||
                        QuoteMode == QuoteMode.OptionalForRead)
                        return BasicExtractString(line);
                    else if (line.StartsWithTrim(quotedStr)) {
                        throw new BadUsageException(
                            string.Format(
                                "The field '{0}' has spaces before the QuotedChar at line {1}. Use the TrimAttribute to by pass this error. Field String: {2}",
                                FieldInfo.Name,
                                line.mReader.LineNumber,
                                line.CurrentString));
                    }
                    else {
                        throw new BadUsageException(
                            string.Format(
                                "The field '{0}' does not begin with the QuotedChar at line {1}. You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field. Field String: {2}",
                                FieldInfo.Name,
                                line.mReader.LineNumber,
                                line.CurrentString));
                    }
                }
            }
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:60,代码来源:DelimitedField.cs


示例8: 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);

            }
        }
开发者ID:jalchr,项目名称:FileHelpers,代码行数:59,代码来源:FieldBase.cs


示例9: AssignFromString

        internal object AssignFromString(ExtractedInfo fieldString, LineInfo line)
        {
            object val;

            var extractedString = fieldString.ExtractedString();
            var trimmedBoth = false;
            switch (TrimMode)
            {
                case TrimMode.None:
                    break;

                case TrimMode.Both:
                    extractedString = extractedString.Trim();
                    trimmedBoth = true;
                    //fieldString.TrimBoth(TrimChars);
                    break;

                case TrimMode.Left:
                    extractedString = extractedString.TrimStart();
                    //fieldString.TrimStart(TrimChars);
                    break;

                case TrimMode.Right:
                    extractedString = extractedString.TrimEnd();
                    //fieldString.TrimEnd(TrimChars);
                    break;
            }

            try
            {
                if (ConvertProvider == null)
                {
                    if (IsStringField)
                        val = extractedString;
                    else
                    {
                        // Trim it to use Convert.ChangeType
                        if (trimmedBoth == false)
                            extractedString = extractedString.Trim();

                        if (extractedString.Length == 0)
                        {
                            // Empty stand for null
                            val = GetNullValue(line);
                        }
                        else
                        {
                            val = Convert.ChangeType(extractedString, FieldTypeInternal, null);
                        }
                    }
                }
                else
                {
                    var trimmedString = extractedString;
                    if (trimmedBoth == false)
                    {
                        trimmedString = extractedString.Trim();
                    }

                    if (ConvertProvider.CustomNullHandling == false &&
                        trimmedString.Length == 0)
                    {
                        val = GetNullValue(line);
                    }
                    else
                    {
                        string from = extractedString;
                        val = ConvertProvider.StringToField(from);

                        if (val == null)
                            val = GetNullValue(line);

                    }
                }

                return val;
            }
            catch (ConvertException ex)
            {
                ex.FieldName = FieldInfo.Name;
                ex.LineNumber = line.mReader.LineNumber;
                ex.ColumnNumber = fieldString.ExtractedFrom + 1;
                throw;
            }
            catch (BadUsageException)
            {
                throw;
            }
            catch (Exception ex)
            {
                if (ConvertProvider == null || ConvertProvider.GetType().Assembly == typeof(FieldBase).Assembly)
                    throw new ConvertException(extractedString, FieldTypeInternal, FieldInfo.Name, line.mReader.LineNumber, fieldString.ExtractedFrom + 1, ex.Message, ex);
                else
                    throw new ConvertException(extractedString, FieldTypeInternal, FieldInfo.Name, line.mReader.LineNumber, fieldString.ExtractedFrom + 1, "Your custom converter: " + ConvertProvider.GetType().Name + " throws an " + ex.GetType().Name + " with the message: " + ex.Message, ex);
            }
        }
开发者ID:jalchr,项目名称:FileHelpers,代码行数:96,代码来源:FieldBase.cs


示例10: NullValueNotFoundException

 /// <summary>Creates an instance of an NullValueNotFoundException.</summary>
 /// <param name="message">The exception Message</param>
 /// <param name="line">Line to display in message</param>
 internal NullValueNotFoundException(LineInfo line, string message)
     : base(line, message)
 {
 }
开发者ID:TheJeremyGray,项目名称:FileWatcherService,代码行数:7,代码来源:NullValueNotFoundException.cs


示例11: StringToRecord

        public object StringToRecord(LineInfo line, object[] values)
        {
            if (MustIgnoreLine(line.mLineStr))
                return null;

            for (int i = 0; i < RecordInfo.FieldCount; i++)
            {
                values[i] = RecordInfo.Fields[i].ExtractFieldValue(line);
            }

            try
            {
                // Asign all values via dinamic method that creates an object and assign values
                return CreateHandler(values);
            }
            catch (InvalidCastException ex)
            {
                // Occurrs when the a custom converter returns an invalid value for the field.
                for (int i = 0; i < RecordInfo.FieldCount; i++)
                {
                    if (values[i] != null && !RecordInfo.Fields[i].FieldTypeInternal.IsInstanceOfType(values[i]))
                        throw new ConvertException(null,
                                                   RecordInfo.Fields[i].FieldTypeInternal,
                                                   RecordInfo.Fields[i].FieldInfo.Name,
                                                   line.mReader.LineNumber,
                                                   -1,
                                                   Messages.Errors.WrongConverter
                                                       .FieldName(RecordInfo.Fields[i].FieldInfo.Name)
                                                       .ConverterReturnedType(values[i].GetType().Name)
                                                       .FieldType(RecordInfo.Fields[i].FieldInfo.FieldType.Name)
                                                       .Text
                                                   ,
                                                   ex);
                }
                return null;
            }
        }
开发者ID:jalchr,项目名称:FileHelpers,代码行数:37,代码来源:RecordOperations.cs


示例12: 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;
		}
开发者ID:pjeconde,项目名称:CedForecast,代码行数:34,代码来源:DelimitedField.cs


示例13: 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);
            }
        }
开发者ID:bittercoder,项目名称:FileHelpers,代码行数:34,代码来源:DelimitedField.cs


示例14: GetNullValue

        /// <summary>
        /// Convert a null value into a representation,
        /// allows for a null value override
        /// </summary>
        /// <param name="line">input line to read, used for error messages</param>
        /// <returns>Null value for object</returns>
        private object GetNullValue(LineInfo line)
        {
            if (NullValue == null) {
                if (FieldTypeInternal.IsValueType) {
                    if (IsNullableType)
                        return null;

                    string msg = "Not value found for the value type field: '" + FieldInfo.Name + "' Class: '" +
                                 FieldInfo.DeclaringType.Name + "'. " + Environment.NewLine
                                 +
                                 "You must use the [FieldNullValue] attribute because this is a value type and can't be null or use a Nullable Type instead of the current type.";

                    throw new NullValueNotFoundException(line, msg);
                }
                else
                    return null;
            }
            else
                return NullValue;
        }
开发者ID:rmegal,项目名称:FileHelpers,代码行数:26,代码来源:FieldBase.cs


示例15: ExtractFieldString

		protected abstract ExtractedInfo ExtractFieldString(LineInfo line);
开发者ID:pjeconde,项目名称:CedForecast,代码行数:1,代码来源:FieldBase.cs


示例16: 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);
            }
//.........这里部分代码省略.........
开发者ID:rmegal,项目名称:FileHelpers,代码行数:101,代码来源:FieldBase.cs


示例17: BadUsageException

 /// <summary>Creates an instance of an BadUsageException.</summary>
 /// <param name="message">The exception Message</param>
 /// <param name="line">Line to display in message</param>
 internal BadUsageException(LineInfo line, string message)
     : this(line.mReader.LineNumber, line.mCurrentPos, message)
 {
 }
开发者ID:jonswaino,项目名称:FileHelpers-fork,代码行数:7,代码来源:BadUsageException.cs


示例18: StringToRecord

		internal object StringToRecord(LineInfo line)
		{
			if (MustIgnoreLine(line.mLineStr))
				return null;


			object[] mValues = new object[mFieldCount];

			// array that holds the fields values
			
			for (int i = 0; i < mFieldCount; i++)
			{
				mValues[i] = mFields[i].ExtractValue(line);
			}

#if NET_1_1 || MINI
			object record = CreateRecordObject();
			for (int i = 0; i < mFieldCount; i++)
			{
				mFields[i].mFieldInfo.SetValue(record, mValues[i]);
			}
			
			return record;
#else
			CreateAssingMethods();

            try
            {
                // Asign all values via dinamic method that creates an object and assign values
               return mCreateHandler(mValues);
            }
            catch (InvalidCastException)
            {
                // Occurrs when the a custom converter returns an invalid value for the field.
                for (int i = 0; i < mFieldCount; i++)
                {
                    if (mValues[i] != null && ! mFields[i].mFieldType.IsInstanceOfType(mValues[i]))
                        throw new ConvertException(null, mFields[i].mFieldType, mFields[i].mFieldInfo.Name, line.mReader.LineNumber, -1, "The converter for the field: " + mFields[i].mFieldInfo.Name + " returns an object of Type: " + mValues[i].GetType().Name + " and the field is of type: " + mFields[i].mFieldType.Name);
                }
                return null;
            }
#endif
		}
开发者ID:pjeconde,项目名称:CedForecast,代码行数:43,代码来源:RecordInfo.cs


示例19: AssignFromString

        internal object AssignFromString(ExtractedInfo fieldString, LineInfo line)
        {
            object val;

            switch (mTrimMode)
            {
                case TrimMode.None:
                    break;

                case TrimMode.Both:
                    fieldString.TrimBoth(mTrimChars);
                    break;

                case TrimMode.Left:
                    fieldString.TrimStart(mTrimChars);
                    break;

                case TrimMode.Right:
                    fieldString.TrimEnd(mTrimChars);
                    break;
            }
            
            try
            {

                if (mConvertProvider == null)
                {
                    if (mIsStringField)
                        val = fieldString.ExtractedString();
                    else
                    {
                        // Trim it to use Convert.ChangeType
                        fieldString.TrimBoth(WhitespaceChars);

                        if (fieldString.Length == 0)
                        {
                            // Empty stand for null
                            val = GetNullValue();
                        }
                        else
                        {
                            val = Convert.ChangeType(fieldString.ExtractedString(), mFieldType, null);
                        }
                    }
                }

                else
                {
                    if (mConvertProvider.CustomNullHandling == false &&
                        fieldString.HasOnlyThisChars(WhitespaceChars))
                    {
                        val = GetNullValue();
                    }
                    else
                    {
                        string from = fieldString.ExtractedString();
                        val = mConvertProvider.StringToField(from);

                        if (val == null)
                            val = GetNullValue();

                    }
                }

                return val;
            }
            catch (ConvertException ex)
            {
                throw ConvertException.ReThrowException(ex, mFieldInfo.Name, line.mReader.LineNumber, fieldString.ExtractedFrom + 1);
            }
        }
开发者ID:pjeconde,项目名称:CedForecast,代码行数:71,代码来源:FieldBase.cs


示例20: 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);
//			}


		}
开发者ID:pjeconde,项目名称:CedForecast,代码行数:52,代码来源:FieldBase.cs



注:本文中的FileHelpers.LineInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SQLite.SQLiteCommand类代码示例发布时间:2022-05-24
下一篇:
C# Fiddler.Session类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap