private void VisitStatements(ContentfulClass instance, INode subject) { var statements = instance .GetType() .GetProperties() .Where(p => Attribute.IsDefined(p, typeof(PredicateAttribute))) .Select(p => new { Predicate = this.Graph.CreateUriNode(new Uri(p.GetCustomAttribute <PredicateAttribute>().Uri)), Object = p.GetValue(instance) }) .Where(field => field.Object != null); foreach (var statement in statements) { if (statement.Object is ContentfulClass contentful) { this.VisitObject(subject, statement.Predicate, contentful); } else if (statement.Object is IEnumerable <ContentfulClass> collection) { this.VisitObject(subject, statement.Predicate, collection); } else { this.VisitObject(subject, statement.Predicate, statement.Object.ToString()); } } }
private INode GetId(ContentfulClass instance) { var baseUriAttribute = instance.GetType().GetCustomAttribute <BaseUriAttribute>(); if (baseUriAttribute == null) { throw new Exception($"BaseUriAttribute missing on {instance.GetType()}"); } var id = instance.Sys.Id; if (instance is IUriEntry uriEntry) { id = uriEntry.Uri; } return(this.Graph.CreateUriNode(new Uri(new Uri(baseUriAttribute.Uri), id))); }
private void VisitType(ContentfulClass instance, INode subject) { var classAttribute = instance.GetType().GetCustomAttribute <ClassAttribute>(); if (classAttribute != null) { this.Graph.Assert( subject, this.Graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)), this.Graph.CreateUriNode(new Uri(classAttribute.Uri)) ); } }