public void Immutable() { // Arrange var obj = new SomeImmutableData(new Guid("8d995e6e-af88-4043-8c31-8ba04c6b4298"), 23, "foo bar", null); // Act var dict = DictionaryMaker.Make(obj); // Assert Assert.AreEqual(obj.Id, dict["Id"]); Assert.AreEqual(obj.Integer, dict["Integer"]); Assert.AreEqual(obj.Text, dict["Text"]); Assert.AreEqual(obj.Date, dict["Date"]); }
public void Dictionary() { // Arrange var obj = new Dictionary <string, object> { { "Id", new Guid("8d995e6e-af88-4043-8c31-8ba04c6b4298") }, { "Integer", 23 }, { "Text", "foo bar" }, { "Date", (DateTime?)null } }; // Act var dict = DictionaryMaker.Make(obj); // Assert Assert.AreEqual(obj["Id"], dict["Id"]); Assert.AreEqual(obj["Integer"], dict["Integer"]); Assert.AreEqual(obj["Text"], dict["Text"]); Assert.AreEqual(obj["Date"], dict["Date"]); }
public void Anonymous() { // Arrange var obj = new { Id = new Guid("8d995e6e-af88-4043-8c31-8ba04c6b4298"), Integer = 23, Text = "foo bar", Date = (DateTime?)null }; // Act var dict = DictionaryMaker.Make(obj); // Assert Assert.AreEqual(obj.Id, dict["Id"]); Assert.AreEqual(obj.Integer, dict["Integer"]); Assert.AreEqual(obj.Text, dict["Text"]); Assert.AreEqual(obj.Date, dict["Date"]); }
public void Expando() { // Arrange dynamic obj = new ExpandoObject(); obj.Id = new Guid("8d995e6e-af88-4043-8c31-8ba04c6b4298"); obj.Integer = 23; obj.Text = "foo bar"; obj.Date = (DateTime?)null; // Act // If I use "var dict" here the type of dict is an ExpandoObject... // What on earth is that? IDictionary <string, object> dict = DictionaryMaker.Make(obj); // Assert Assert.AreEqual(obj.Id, dict["Id"]); Assert.AreEqual(obj.Integer, dict["Integer"]); Assert.AreEqual(obj.Text, dict["Text"]); Assert.AreEqual(obj.Date, dict["Date"]); }
/// <summary> /// Makes a ExpandoObject out of the given object. /// </summary> /// <param name="value">Object to become ExpandoObject</param> /// <returns>The ExpandoObject made</returns> public static ExpandoObject ToExpando(this object value) { if (value == null) { throw new ArgumentNullException("value"); } var expando = value as ExpandoObject; if (expando == null) { expando = new ExpandoObject(); var dict = (IDictionary <string, object>)expando; foreach (var kvp in DictionaryMaker.Make(value)) { dict.Add(kvp); } } return(expando); }
/// <inheritdoc /> public Uri ExpandAbsolute <T>(object parameters) { var dictionary = parameters as IDictionary <string, object> ?? DictionaryMaker.Make(parameters); return(this.ExpandAbsolute <T>(dictionary)); }