/// <summary>Wraps the entity as a given statically typed type.</summary> public static TInterface AsEntity <TInterface>(this IEntity entity) where TInterface : class, IEntity { TInterface result; entity = UnwrapProxy(entity); if (entity is TInterface) { result = (TInterface)entity; } else if (entity is Entity) { result = ((Entity)entity).AsEntity <TInterface>(); } else if (entity is EntityProxy) { result = ((EntityProxy)entity).AsEntity <TInterface>(); } else { result = entity.ActLike <TInterface>(); } return(result); }
private static IEnumerable <IOperation> CreateTemplatedOperation( IHydraResource owner, IDereferencableLink relationResource, IEntity @object, Iri type) { foreach (var operation in relationResource.SupportedOperations) { var result = operation.Copy(GetNextIri("Operation")); result.Type.AddIfNotExist(type); result.Type.AddIfNotExist(hydra.IriTemplate); var templatedOperation = result.ActLike <ITemplatedOperation>(); var proxy = templatedOperation.Unwrap(); proxy.SetProperty(IriTemplatePropertyInfo, @object.ActLike <IIriTemplate>()); result = templatedOperation; owner.Operations.Add(result); yield return(result); } }