private static SingleRelation CreateRelation(object model, PropertyInfo property, IHateoasLink hateoasLink) { if (model == null) { return new SingleRelation { Data = new JsonApiEntity { Type = property.DeclaringType.Name } } } ; var id = property.GetValue(model).ToString(); return(new SingleRelation { Links = new Dictionary <string, string> { { "self", hateoasLink.LinkPath ?? hateoasLink.Template.HenriFormat(model) } }, Data = new JsonApiData { Type = model.GetType().Name, Id = id } }); }
private static CollectionRelation CreateRelations(object model, Type propertyType, IHateoasLink hateoasLink) { var result = new CollectionRelation { Links = new Dictionary <string, string> { { "self", hateoasLink.LinkPath } }, }; if (model == null) { return(result); } var collection = ((IEnumerable <object>)model).ToList(); if (!collection.Any()) { return(result); } var idProperty = GetIdProperty(propertyType, propertyType.GetProperties()); result.Data = collection.Select(p => new JsonApiData { Type = propertyType.Name, Id = GetValueFromModel(p, idProperty) }).ToList(); return(result); }
public void Dispose() { Sut = null; GC.SuppressFinalize(this); }