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 void VisitSubject(ContentfulClass instance)
        {
            var subject = this.GetId(instance);

            this.VisitType(instance, subject);

            this.VisitStatements(instance, subject);
        }
        private void VisitObject(INode subject, IUriNode predicate, ContentfulClass item)
        {
            var @object = this.GetId(item);

            this.Graph.Assert(subject, predicate, @object);

            if (!this.Graph.GetTriplesWithSubject(@object).Any())
            {
                this.VisitSubject(item);
            }
        }
        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))
                    );
            }
        }
        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)));
        }
 public Processor(ContentfulClass instance) : this(instance.AsEnumerable())
 {
 }