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 3278686
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:30:30+00:00 2026-05-17T19:30:30+00:00

I have a number of objects that I need to create and add to

  • 0

I have a number of objects that I need to create and add to an array. However the code below seems dirty and difficult to maintain in the long run. What I’m thinking is, I should store the Name and Value properties in a table and build each comCommand object at runtime.

However, I’m not exactly sure what the best method to about doing this… Reflection, Activator.CreateInstance or some kind of object factory?

Thanks in advance.

 var engine = new comCommand() { commandName = "-e", commandValue = "PNetTNative" };
 var outputFile = new comCommand() { commandName = "-f", commandValue = OutputFile };
 var groupSize = new comCommand() { commandName = "-GroupSizeParamInput1ParamsIn", commandValue = GroupSize };
 var pagesPerSheet = new comCommand() { commandName = "-PagesPerSheetParamInput1ParamsIn", commandValue = PagesPerSheet };
 var outputFileName = new comCommand { commandName = "-OutputFileNameParamInput1ParamsIn", commandValue = OutputFileName };
 var duplex = new comCommand { commandName = "-DuplexParamInput1ParamsIn", commandValue = Duplex };
 var processId = new comCommand { commandName = "-ProcessIDParamInput1ParamsIn", commandValue = ProcessID };

 var request = new comRunWorkFlowReq(); 
 request.command = new[] { engine, outputFile, groupSize, pagesPerSheet, outputFileName, duplex, processId };
  • 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-17T19:30:30+00:00Added an answer on May 17, 2026 at 7:30 pm

    Create a command constructor (as Kirk suggested) and keep it as you have: multiple comCommand(“-e”,”PNetTNative”) etc calls.

    The reason for keeping it in code is you get compiler-time type and error checking… Yes, you can do it at runtime (various methods) but for just 7 declarations, it’s best to keep it at compile time.

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

Sidebar

Related Questions

I have a Vector that holds a number of objects. My code uses a
We have a number of data objects that realize INotifyPropertyChanged to allow for WPF
The question is this. I have a number of persisted objects that I'll pull
I have a LinkedList that contains many objects. How can I find the number
I have an array made of unlimited number of objects. These objects have the
I have a tableview that is successfully incorporating an NSFetchedResultsController. However, I need the
I have an array that created 5 objects. Each object has two strings and
I have a class that spawns an arbitrary number of worker object that compute
I have a stdClass object created from json_decode that won't return the right number
I have a number of objects, all from the same class(ColorNum) Each object has

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.