public void GetPropertiesWithNullTarget() { var result = PropertyValueLister.GetProperties(null); Assert.IsNotNull(result); Assert.IsFalse(result.GetEnumerator().MoveNext()); }
public void GetPropertiesOnAnoymousObject() { var result = PropertyValueLister.GetProperties(new { name = "123", jack = 100 }).ToList(); Assert.IsNotNull(result); Assert.IsTrue(result[0].Key == "name" && (string)result[0].Value == "123"); Assert.IsTrue(result[1].Key == "jack" && (int)result[1].Value == 100); }
/// <summary> /// Initializes a new instance of the <see cref="ValueDictionary"/> class. /// </summary> /// <param name="items">The items.</param> protected ValueDictionary(object items) { if (items == null) { return; } if (items is string || items.GetType().IsValueType) { throw new InvalidOperationException("A string or value type was passed to a method that expected a parameter value dictionary. These parameters are normally used for anonymous objects to represent key/value pairs as arguments. Ensure that the right method overload was called."); } foreach (var pair in PropertyValueLister.GetProperties(items)) { Add(pair.Key, pair.Value); } }