private IResource EnsureTypeCastedFor(IResource resource) { var result = resource; var typeToCast = typeof(IResource); foreach (var type in resource.Type) { var entityMapping = resource.Context.Mappings.FindEntityMappingFor(resource, type); if (entityMapping?.Type != null && entityMapping.Type != typeToCast && typeToCast.IsAssignableFrom(entityMapping.Type)) { typeToCast = entityMapping.Type; } } if (typeToCast != typeof(IResource)) { result = (IResource)resource.ActLike(typeToCast); } return(result); }
private static IEnumerable <IDereferencableLink> CreateLink( IHydraResource owner, IDereferencableLink relationResource, IResource @object, Iri type) { var result = relationResource.Copy(GetNextIri(type.ToString().Replace(hydra.Namespace, String.Empty))); var proxy = result.Unwrap(); proxy.SetProperty(ResourceExtensions.TargetPropertyInfo, @object); result.Type.AddIfNotExist(type); result.Type.Remove(type == hydra.TemplatedLink ? hydra.Link : hydra.TemplatedLink); if (type == hydra.TemplatedLink && @object != null) { var templatedLink = result.ActLike <ITemplatedLink>(); proxy.SetProperty(IriTemplatePropertyInfo, @object.ActLike <IIriTemplate>()); result = templatedLink; } owner.Links.Add(result); return(new[] { result }); }