473,396 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Parsing Command-Line Arguments with InstallContext

I'm using the InstallContext class to parse the command-line arguments of a console application. The arguments are in the form of "-file=myFile.txt -flag", and the InstallContext object gives me what I need through the Parameters and IsParameterTrue properties.

However, I can't find any documentation or code samples that confirm that this is an acceptable use of the InstallContext class. I understand the need to use Regex or some other means to parse more complex command-line arguments, but I'm surprised to find no mention of this simple parsing alternative. Is there anything wrong with using InstallContext for this purpose

using System;
using System.Configuration.Install;
using System.Collections.Specialized;

class MyClass
{
public static void Main(string[] args)
{
InstallContext context = new InstallContext(null, args);
StringDictionary parameters = context.Parameters;

string file = parameters["file"];
bool flag = context.IsParameterTrue("flag");

Console.WriteLine("file = {0}", file);
Console.WriteLine("flag = {0}", flag);
}
}
Nov 16 '05 #1
1 9628
"=?Utf-8?B?bXJpZWRlbA==?=" <an*******@discussions.microsoft.com>
wrote in news:D9**********************************@microsof t.com:
I'm using the InstallContext class to parse the command-line
arguments of a console application. The arguments are in the
form of "-file=myFile.txt -flag", and the InstallContext object
gives me what I need through the Parameters and IsParameterTrue
properties.

However, I can't find any documentation or code samples that
confirm that this is an acceptable use of the InstallContext
class. I understand the need to use Regex or some other means to
parse more complex command-line arguments, but I'm surprised to
find no mention of this simple parsing alternative. Is there
anything wrong with using InstallContext for this purpose?


I looked at the underlying source code for InstallContext with
Reflector (http://www.aisto.com/roeder/DotNet/). As far as I can
see, InstallContext doesn't produce any side effects, so it looks
safe to use.

Thanks for bringing this class to light. With over 5000 classes in
the framework, it's too easy to overlook a gem like this.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: InsaneScouter | last post by:
I am running a shell command via a php started ssh connection to a mail server. I need to grab the data the shell command displays and then load them into variables or an array ... Can anyone give...
4
by: Uwe Ziegenhagen | last post by:
Hello, my fellows and me implement a c++ tool that is able to divide blank/tab separated files into <number>, <text>, <c-singlelinecomment> and <multilinecomment>. So far it's not working bad,...
9
by: Rob | last post by:
I am trying to write a program with VC++ 6.0 to read a txt file which looks like this: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 ...
6
by: John Paulsson | last post by:
Is there a C# pattern or perhaps a .NET framework way of parsing a command lines, supporting quoted filepaths etc? (I'm not talking about the current applications command arguments. I've got...
0
by: Seth | last post by:
First off, my apologies if this is in the wrong newsgroup, but I hope I'm close enough. I'm trying to do some parsing of a CSV file using OleDbConnection, but for some reason, when I populate my...
3
by: David Svoboda | last post by:
I have a server program that takes commands and acts on them. The server program can also take these commands from an input file or standard input (mainly for testing purposes). As such, I often...
2
by: JaythePCguy | last post by:
Hi, I am trying to write a text parser to group all nonprintable and control characters, spaces and space delimited words in different groups using Regex class. Using a parsing of...
4
by: Jim Langston | last post by:
In my program I am accepting messages over the network and parsing them. I find that the function that does this has gotten quite big, and so want to break the if else code into functions. I...
2
by: Andy | last post by:
Hi guys, I'm writing a program with a feature of accepting user input as command text and parsing it to correct function calls...example: "5 minutes later"/"5 min later"/"5 minute...
8
by: lawrence k | last post by:
I have to parse some FTP logs, which are full of several thousand lines like this: Thu Sep 4 11:39:04 2008 FTP command: Client "74.231.146.2", "TYPE A" Thu Sep 4 11:39:04 2008 FTP...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.