private static EasyAttributeValue FromClass <T>(T obj) where T : class { var classProperties = new Dictionary <string, AttributeValue>(); var objectProperties = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var property in objectProperties) { var value = property.GetValue(obj); EasyAttributeValue attributeValue; var type = value.GetType(); if (IsEnumerable(type)) { attributeValue = FromCollection(value as IEnumerable <object>); } else if (IsClass(type)) { attributeValue = FromObject(value); } else if (IsEnum(type)) { attributeValue = new EasyAttributeValue((Enum)value); } else { attributeValue = FromPrimitive(value); } classProperties.Add(property.Name, attributeValue); } return(new EasyAttributeValue(classProperties)); }
private static EasyAttributeValue FromPrimitive(object value) { EasyAttributeValue attributeValue; switch (value) { case int v: attributeValue = new EasyAttributeValue(v); break; case float v: attributeValue = new EasyAttributeValue(v); break; case double v: attributeValue = new EasyAttributeValue(v); break; case string v: attributeValue = new EasyAttributeValue(v); break; case decimal v: attributeValue = new EasyAttributeValue(v); break; case bool v: attributeValue = new EasyAttributeValue(v); break; case DateTime v: attributeValue = new EasyAttributeValue(v); break; case DateTimeOffset v: attributeValue = new EasyAttributeValue(v); break; default: throw new Exception(); } return(attributeValue); }