Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 2.35 KB

README.md

File metadata and controls

25 lines (19 loc) · 2.35 KB

Ockham.Data

Basic data inspection and conversion utilities. Part of the Ockham.Net project.

The Problem

Every Ockham component should solve a clear problem that is not solved in the .Net BCL, or in the particular libraries it is meant to augment.

The utilities in this library provide robust, configurable data inspection and conversion utilities. These are particularly useful when serializing and deserializing to databases or other external sources, and when working with dynamic data.

Data Conversion

The existing basic data conversions available from the System.Convert and Microsoft.VisualBasic.CompilerServices.Conversions classes fail in several cases that arise frequently when working with serialization and deserialization:

  • Converting to and from DBNull
  • Converting to and from Nullable<T> values
  • Converting to and from enums
  • Converting to and from Guids
  • Converting to any target type with generic method syntax (both System.Convert.ChangeType and Conversions.ChangeType are non-generic methods that require a runtime type value and return a object)

The different conversion and inspection functions of the Convert static class and Converter instance class, along with the various flags of the ConvertOptions enumeration, provide succinct and intuitive conversions that can also be adjusted for the desired specifics, such as:

  • Treating an empty string as null (or not)
  • Recognizing hexadecimal strings (or not)
  • Converting null values to the default value of a value type (or not)
  • Coercing any value to a particular target type, with or without an explicit fallback value (or not)

Type Inspection

The BCL lacks succinct methods for checking if a value or a type is numeric, whether a type implements a variation of an open generic interface, or whether a type is a constructed form of a open generic class