Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 420077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:50:26+00:00 2026-05-12T18:50:26+00:00

Based on http://alexreg.wordpress.com/2009/05/03/strongly-typed-csv-reader-in-c/ , I created a DLL which can read different file types.

  • 0

Based on http://alexreg.wordpress.com/2009/05/03/strongly-typed-csv-reader-in-c/, I created a DLL which can read different file types. I also have unit tests that run successfully. I create a struct and use it as the generic type.

Anyway, when I compile, I get a warning on each of the struct fields. For example: field ‘FileReader.Tests.CsvReader.Record.Field1’ is never assigned to, and will always have its default value 0

I am in fact setting the value with SetValueDirect() and when I run through the tests or debug the code, I can verify that. Why is it giving me that error then, and how can I avoid or fix it?

Here is some basic code to give you an idea. I’m guessing I haven’t provided enough, but hopefully someone has a clue.

public abstract class FileReader<TRecord> : IDisposable where TRecord : struct
{
        public TRecord? ReadRecord()
        {
            List<string> fields;
            string rawData;

            this.recordNumber++;
            while (this.ReadRecord(this.fieldTypeInfoList.Length, out fields, out rawData))
            {
                try
                {
                    // Insert the current record number to the beginning of the field list
                    fields.Insert(0, this.recordNumber.ToString(CultureInfo.InvariantCulture));

                    // Convert each field to its correct type and set the value
                    TRecord record = new TRecord();
                    FieldTypeInfo fieldTypeInfo;
                    object fieldValue;

                    // Loop through each field
                    for (int i = 0; i < this.fieldTypeInfoList.Length; i++)
                    {
                        fieldTypeInfo = this.fieldTypeInfoList[i];

                        bool allowNull = fieldTypeInfo.AllowNull == null ? this.AllowNull : fieldTypeInfo.AllowNull.Value;
                        if (i >= fields.Count && !allowNull)
                        {
                            // There are no field values for the current field
                            throw new ParseException("Field is missing", this.RecordNumber, fieldTypeInfo, rawData);
                        }
                        else
                        {
                            // Trim the field value
                            bool trimSpaces = fieldTypeInfo.TrimSpaces == null ? this.TrimSpaces : fieldTypeInfo.TrimSpaces.Value;
                            if (trimSpaces)
                            {
                                fields[i] = fields[i].Trim();
                            }

                            if (fields[i].Length == 0 && !allowNull)
                            {
                                throw new ParseException("Field is null", this.RecordNumber, fieldTypeInfo, rawData);
                            }

                            try
                            {
                                fieldValue = fieldTypeInfo.TypeConverter.ConvertFromString(fields[i]);
                            }
                            catch (Exception ex)
                            {
                                throw new ParseException("Could not convert field value", ex, this.RecordNumber, fieldTypeInfo, rawData);
                            }

                            fieldTypeInfo.FieldInfo.SetValueDirect(__makeref(record), fieldValue);
                        }
                    }

                    return record;
                }
                catch (ParseException ex)
                {
                    ParseErrorAction action = (ex.FieldTypeInfo.ParseError == null) ? DefaultParseErrorAction : ex.FieldTypeInfo.ParseError.Value;

                    switch (action)
                    {
                        case ParseErrorAction.SkipRecord:
                            continue;

                        case ParseErrorAction.ThrowException:
                            throw;

                        case ParseErrorAction.RaiseEvent:
                            throw new NotImplementedException("Events are not yet available", ex);

                        default:
                            throw new NotImplementedException("Unknown ParseErrorAction", ex);
                    }
                }
            }

            return null;
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:50:26+00:00Added an answer on May 12, 2026 at 6:50 pm

    The compiler is never going to be able to spot reflection. By definition, by using reflection you have stepped outside the compiler.

    IMO, though, this is a bad use of structs – that looks very much like it should be working on classes…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which popular websites out there support an HTTP based API? I am looking for
I'm working on a web based application which uses a JSON over HTTP based
Based on http://api.jquery.com/ajaxComplete/ .ajaxComplete( handler(event, XMLHttpRequest, ajaxOptions) ) .ajaxStart( handler(event) ) To my knowledge
I'm going to do a wpf application using MVVM(It based on http://www.codeproject.com/KB/WPF/MVVMQuickTutorial.aspx ). This
Based on http://www.cplusplus.com/reference/stl/vector/vector/ explicit vector ( const Allocator& = Allocator() ); This vector constructor
Based on http://www.mredkj.com/javascript/nfbasic2.html , following code will result in 5.6e+2 . num = 555.55;
Based on http://jqueryui.com/demos/sortable/#placeholder I am working on a drag and drop interface that allows
Based on http://tutorialzine.com/2011/06/beautiful-portfolio-html5-jquery/ tutorial I am trying to implement a sort function to my
Based on http://ie.microsoft.com/testdrive/HTML5/ECMAScript5Array/Default.html , I thought IE9 supports indexOf in array but the following
I thought I understood the concept of cursors and queries based on http://code.google.com/appengine/docs/python/datastore/queryclass.html but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.