NMyVision.DataDictionary 1.0.3.9

A dictionary wrapper that converts all complex elements to Dictionary<string, object> or IEnumerable<Dictionary<string, object>> objects.

Install-Package NMyVision.DataDictionary -Version 1.0.3.9
dotnet add package NMyVision.DataDictionary --version 1.0.3.9
<PackageReference Include="NMyVision.DataDictionary" Version="1.0.3.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NMyVision.DataDictionary --version 1.0.3.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

DataDictionary

A dictionary wrapper that converts all complex values to Dictionary<string, object> or IEnumerable<Dictionary<string, object>> objects.

Furthermore object in <string, object> will always be one of the following:

  • a simple type (string, boolean, int, DateTime, etc...)
  • an array of type
    • DataDictionary
    • simple type
  • DataDictionary

Example

Anonymous Object example

var source = new {
    Date = DateTime.Now,
    Target = new {
        Name = "PrepublishScript",
        BeforeTargets = "PrepareForPublish"
    },
    Exec = new[] {
        new { Command = "npm install" },
        new { Command = "bower install" },
        new { Command = @"node node_modules\gulp\bin\gulp.js" }
    }
};
dd = DataDictionary.From(source);

Generates:

Sample result

Class example

class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
    public IEnumerable<Person> Children { get; set; }
}

void Main()
{

  var person = new Person()
  {
    Name = "Charlotte",
    Age = 34,
    Children = new [] {
      new Person { Name = "Jane" , Age = 5 }
    }
 };

  var dd = DataDictionary.From(person);
}

Generates:

Sample result

JSON parsing

string json = @"{
  'title': 'Person',
  'type': 'object',
    'properties': {
    'firstName': {
      'type': 'string'
    },
    'lastName': {
      'type': 'string'
    },
    'age': {
      'description': 'Age in years',
      'type': 'integer',
      'minimum': 0,
      'foo': null
    }
  },
  'required': ['firstName', 'lastName'],
  'people': [ ]
}";

var dd = DataDictionary.ParseJson(json);

Sample result

Helper methods

var dd = DataDictionary.ParseJson(json);
dd.Flatten();

Sample result

dynamic d = dd.ToExpandoObject();
d.properties.age.type; 

// integer

DataDictionary

A dictionary wrapper that converts all complex values to Dictionary<string, object> or IEnumerable<Dictionary<string, object>> objects.

Furthermore object in <string, object> will always be one of the following:

  • a simple type (string, boolean, int, DateTime, etc...)
  • an array of type
    • DataDictionary
    • simple type
  • DataDictionary

Example

Anonymous Object example

var source = new {
    Date = DateTime.Now,
    Target = new {
        Name = "PrepublishScript",
        BeforeTargets = "PrepareForPublish"
    },
    Exec = new[] {
        new { Command = "npm install" },
        new { Command = "bower install" },
        new { Command = @"node node_modules\gulp\bin\gulp.js" }
    }
};
dd = DataDictionary.From(source);

Generates:

Sample result

Class example

class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
    public IEnumerable<Person> Children { get; set; }
}

void Main()
{

  var person = new Person()
  {
    Name = "Charlotte",
    Age = 34,
    Children = new [] {
      new Person { Name = "Jane" , Age = 5 }
    }
 };

  var dd = DataDictionary.From(person);
}

Generates:

Sample result

JSON parsing

string json = @"{
  'title': 'Person',
  'type': 'object',
    'properties': {
    'firstName': {
      'type': 'string'
    },
    'lastName': {
      'type': 'string'
    },
    'age': {
      'description': 'Age in years',
      'type': 'integer',
      'minimum': 0,
      'foo': null
    }
  },
  'required': ['firstName', 'lastName'],
  'people': [ ]
}";

var dd = DataDictionary.ParseJson(json);

Sample result

Helper methods

var dd = DataDictionary.ParseJson(json);
dd.Flatten();

Sample result

dynamic d = dd.ToExpandoObject();
d.properties.age.type; 

// integer

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.3.9 200 9/9/2018
1.0.3.8 246 7/5/2018