Introduction >

UnitParser code (.NET/C#) >


NumberParser code (.NET/C#) >

DateParser code (.NET/C#) >

FlexibleParser code

UnitParser code (.NET/C#) >
UnitParser is the first part of FlexibleParser, which is my first relevant open-source project. That's why I was especially motivated to do a good work on all the aspects of the development, including those which aren't my strongest suits. Note that I specialise in building efficient algorithms and, basically, in making sure that everything works exactly as expected. Although I have also to take care of further issues like code clarity or documentation (public comments and external documents), my usual performance on these fronts is notably worse.

The fact of dealing with units of measurement (mainly when developing an as comprehensive tool as UnitParser) adds one further layer of complexity on the documentation front, via having to account for relevant amounts of hardcoded information. Logically, I also applied the aforementioned ideas of paying special attention at documentation and code-cleanness aspects on this specific front; that's why UnitParser contains a relevant amount of high quality information about units of measurement. All this data is well commented and stored in human-friendly structures, what allows people from any programming background to get valuable insights.

The main public variables containing hardcoded information about units of measurement are stored in the /Keywords/Public/ folder, mostly in the following resources:
  • Units enum, which includes all the supported named units.
  • UnitSymbols class, which contains all the string constants storing the primary symbol, abbreviation or string representation associated with each named unit.
  • ConversionFactors class, which contains all the decimal unit conversion factors with respect to the reference for the given type (e.g., metre for length).
  • Keywords_Public_Prefixes.cs, which includes the main information about all the supported unit prefixes.
  • UnitTypes enum, where all the supported unit types are listed.

The main private variables are stored in the /Keywords/Private/ folder, mostly in the following resources:
  • AllUnits dictionary, which provides a user-friendly way to update the relationships among units, systems, types and conversion factors. At runtime and right after all its information has been stored in smaller and more specific collections, this dictionary is deleted.
  • Keywords_Private_Units.cs, where the dictionaries relating the units with their symbols are stored. It also contains various collections describing non-standard unit behaviours.
  • Keywords_Private_Prefixes.cs, which contains all the dictionaries relating prefixes with their symbols and values. It also includes collections with units using prefixes in a non-standard way.
  • Keywords_Private_Compounds.cs, where all the main compound-related classifications and definitions are stored.