public void Serialize(object graph, IDictionary dictionary) { if (graph == null) { return; } if (dictionary == null) { throw new ArgumentNullException("dictionary"); } dictionary.Add("@type", graph.GetType().AssemblyQualifiedName); var properties = graph.GetType().GetProperties(); foreach (var property in properties) { if (!property.CanRead) { continue; } if (TypeExtension.IsScalarType(property.PropertyType)) { dictionary.Add(property.Name.ToLowerInvariant(), property.GetValue(graph)); } } }
public void ScalarTypeTest() { Assert.True(TypeExtension.IsScalarType(typeof(string))); Assert.True(TypeExtension.IsScalarType(typeof(Guid))); Assert.True(TypeExtension.IsScalarType(typeof(DateTime))); Assert.True(TypeExtension.IsScalarType(typeof(TimeSpan))); Assert.True(TypeExtension.IsScalarType(typeof(Gender))); Assert.True(TypeExtension.IsScalarType(typeof(int[]))); Assert.False(TypeExtension.IsScalarType(typeof(IList <int>))); }