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

  • Home
  • SEARCH
  • 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 6342395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:14:00+00:00 2026-05-24T20:14:00+00:00

I am trying to design a class of static objects. For example lets assume

  • 0

I am trying to design a class of static objects. For example lets assume they are to represent car models. This is how I started out:

public class CarModel
{
    internal CarModel(string manufacturer, string modelName, double seconds0To60, double maxMPH)
    {
        Manufacturer = manufacturer;
        ModelName = modelName;
        Seconds0To60 = seconds0To60;
        MaxMPH = maxMPH;
    }
    public string Manufacturer { get; private set; }
    public string ModelName { get; private set; }
    public double Seconds0To60 { get; private set; }
    public double MaxMPH { get; private set; }

    public override string ToString() { return Manufacturer + " " + ModelName; }

    static public readonly CarModel AlfaRomeo_Brera = new CarModel("Alfa Romeo", "Brera 1.75 TBi 3d", 7.5, 146.0);

    static public readonly CarModel AlfaRomeo_Giulietta = new CarModel("Alfa Romeo", "Giulietta 1.4 TB Lusso 5d", 9.1, 121.0);

    static public readonly CarModel Ford_Focus = new CarModel("Ford", "Focus 2.5 RS 3d", 5.2, 163.0);

    static public readonly CarModel Ford_Mondeo = new CarModel("Ford", "Mondeo Saloon 2.0 Zetec 4d", 9.7, 130.0);

    static public readonly CarModel Honda_Accord = new CarModel("Honda", "Accord Tourer 2.4 i-VTEC EX 5d (Adas)", 7.6, 138.0);

    static public readonly CarModel Honda_Civic = new CarModel("Honda", "Civic Hatchback 1.8 i-VTEC Type S 3d Auto", 10.6, 127.0);
}

This approach seemed to work well for the 6 test models as above. However, it now seems that I have approximately 500 car models to input and there are many properties for each car model. The car data I have is currently in an Excel spreadsheet. So the question is how best to add this data to my dll?

I would like all car models to be compiled into the assembly dll if that is possible. So I would prefer not to use a database. I had a brief look at some dynamic enum posts – perhaps some automatic code generation might work? Or perhaps I could copy and paste my data into a resource file? Or maybe there is someway to add a DataSet or DataTable to the project that contains this static data?

I think the static readonly properties in the example class above will need to be changed for a more sophisticated approach to accessing the list of models.

Please let me know your suggestions,
Thanks.

  • 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-24T20:14:01+00:00Added an answer on May 24, 2026 at 8:14 pm

    Since you said you would prefer the models to be compiled into the assembly, I would look into T4. Here is a tutorial http://msdn.microsoft.com/en-us/library/dd820614.aspx. The basic approach is to:

    1. define your models in csv
    2. create a t4 template which reads the csv, writes the data at the top of the class(internal CarModel, etc), iterates through the data, writing out “static public your property” for each line

    Every time you build your project, the t4 template will run, generating the class for you.

    Edit, here is a sample .tt file which solves the problem:

    <#@ template debug="false" language="C#" #>  
    <#@ output extension=".cs" #>  
    <#@ import namespace="System" #>  
    <#@ import namespace="System.IO" #>  
    <#@ import namespace="System.Collections.Generic" #>  
    <#@ import namespace="System.Text.RegularExpressions" #>  
    
    namespace Play.Helpers  
    {
    
        public class CarModel
        {
            internal CarModel(string manufacturer, string modelName, double seconds0To60, double maxMPH)
            {
                Manufacturer = manufacturer;
                ModelName = modelName;
                Seconds0To60 = seconds0To60;
                MaxMPH = maxMPH;
            }
            public string Manufacturer { get; private set; }
            public string ModelName { get; private set; }
            public double Seconds0To60 { get; private set; }
            public double MaxMPH { get; private set; }
    
            public override string ToString() { return Manufacturer + " " + ModelName; }
    
            <#
            String path = "D:\\My Documents\\Visual Studio 2010\\Projects\\Play\\Play\\Content\\testdata.csv";
            List<string[]> parsedData = new List<string[]>();
    
                    try
                    {
                        using (StreamReader readFile = new StreamReader(path))
                        {
                            string line;
                            string[] row;
    
                            while ((line = readFile.ReadLine()) != null)
                            {
                                row = line.Split(',');
                                #>
                                static public readonly CarModel <#=(String)row[0].Replace(" ", "_")#>_<#=Regex.Replace(row[1], @"[\.\(\)-]", "_").Replace(" ", "_")#>  = new CarModel("<#=(String)row[0]#>", "<#=row[1]#>", <#=row[2]#>, <#=row[3]#>);
                                <#
                                parsedData.Add(row);
                            }
                        }
                    }catch(Exception e)
                    {
                        //left as an excercise for the reader
                    }
    
            #>
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to work out the best way to design a class that
I'm trying to design a policy-based class, where a certain interface is implemented by
I'm trying to generate a diagram for a design document. I've generated a class
I'm trying to design a class which can update a reference to an object
I'm trying to design a class which has two vectors of large sequences. std::vector<double>
I think this explains my question well enough: public class Model { public static
I'm trying to work out how to best complete my design work on my
Just need help as I have been trying sort this out for ages now.
I'm looking for solution of C++ class design problem. What I'm trying to achieve
I have something like this: class Base { public: static int Lolz() { return

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.