Simple class library that converts a class into a matching dictionary using reflection.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
C2DTests
Class2Dictionary
.gitignore
Class2Dictionary.sln
LICENSE
README.md

README.md

Class2Dictionary

Class2Dictionary is a simple utitlity extension method to convert a class into a dictionary.

Usage

C2D is an extension method and will work on any object that inherits the IC2D interface.

public class SampleClass : IC2D
{
   public int Id { get; set; }
   public string FirstName { get; set; }
   public string LastName { get; set; }
   public string Company { get; set; }
}

It can be used like this:

var sampleClass = new SampleClass();
var dictionary = sampleClass.ConvertC2D();

It returns a dictionary containing the property names as the keys, and the property values as the values.

I built it for use in sending POST requests but thought someone else might find it useful.

Wish List

  • Serialize to JSON
  • Serialize to name/value string (FirstName=Tom,LastName=Swift)
  • Make the keys generic so the dictionary can hold any object as a value