Esempio n. 1
0
        private IJsonMetadata GetMetadata(IMetadataBuilderContext context, MetadataIdentity identity)
        {
            MetadataIdentity  parentIdentity = identity.Parent();
            IJsonMetadata     parent         = context.GetMetadata <IJsonMetadata>(parentIdentity.Name) ?? this.GetMetadata(context, parentIdentity);
            IRelationMetadata relation       = identity.GetMetadata <IRelationMetadata>();

            if (parent == null || relation == null)
            {
                return(null);
            }

            JsonMetadata metadata = new JsonMetadata(relation);

            if (this.HasJsonAttribute(relation) || relation.HasFlag(RelationMetadataFlags.Item))
            {
                metadata.MemberOf = metadata;
                metadata.IsRoot   = true;
                metadata.Path     = "$";
            }
            else
            {
                metadata.MemberOf = parent.MemberOf;
                metadata.IsRoot   = false;
                metadata.Path     = $"{parent.Path}.{this.GetPropertyNameFromContract(metadata)}";
            }

            context.AddMetadata <IJsonMetadata>(metadata);

            return(metadata);
        }
Esempio n. 2
0
        public void Initialize(IMetadataBuilderContext context)
        {
            JsonMetadata metadata = new JsonMetadata(context.Relation);

            metadata.MemberOf = metadata;
            metadata.Path     = "$";
            metadata.IsRoot   = true;

            context.AddMetadata <IJsonMetadata>(metadata);
        }
Esempio n. 3
0
        public void Initialize(IMetadataBuilderContext context)
        {
            IRelationMetadata relation = context.Identity.GetMetadata <IRelationMetadata>();

            if (relation == null)
            {
                throw MetadataNotFoundException.FromMetadata <IRelationMetadata>(context.Identity);
            }

            JsonMetadata metadata = new JsonMetadata(relation);

            metadata.MemberOf = metadata;
            metadata.Path     = "$";
            metadata.IsRoot   = true;

            context.AddMetadata <IJsonMetadata>(metadata);
        }