Automate reading simple POCOs from command line. And by simple I mean really simple:
- either built-in types;
- or collection of scalar values.
It is more of a fun project, a lame kata, if you will, to practice the basics, but it proved useful in some manual testing scenarios as well. I do hope it will help others as well.
Supported built-in types:
intuintshortushortlongulongstringboolfloatdoubledecimalcharbytesbyteSystem.Guid.
Supported collection types (typed colllections, type can be any of the above):
- typed enumerables:
IEnumerable<T>which is populated as aList<T>; - lists -
IList<T>andList<T>; - typed arrays -
T[].
- public instance properties are searched for, inheritance is observed;
- must have a public parameterless constructor;
- most of the values are parsed with the available
TryParsemethods for that respective type, with the following exceptions:- for a
Guid, if enteringnew(), a new guid will be generated, otherwise has to be manually inserted as everything else; - for
bool, the following values are also supported:- truthy values:
yes,da,1; - falsy values:
no,nu,0.
- truthy values:
- for a
- default values for regular properties are whatever they are when the object gets created;
- default value types for the element of a collection is:
Activator.CreateInstance( elementType )if it's a value type;nullif not.
- collection must have sizes specified up-front;
- one may decorate properties with
System.ComponentModel.DescriptionAttributeto customize the prompts, although one does not have to.
I used this nifty little class by @raminrahimzada to provide colored console output when rendering the prompts.
No library to install. Just copy the source files wherever you need and then do something like this:
PocoCommandLineReader<CustomerSummary> reader = new PocoCommandLineReader<CustomerSummary>();
CustomerSummary obj = reader.Read( "Read customer summary" );Also see samples (CSharp-PocoCommandLineReader.SampleUsage).
Nothing: unless I find something's wrong with it or that I want some improvements, I don't plan on developing on a regular basis. Feel free to fork and use as you like.
