예제 #1
0
        /// <summary>
        /// Constructs an address by extracting it from a container or a content item where AddressComponent attributes were
        /// used to map content fields to the address
        /// </summary>
        /// <param name="cont">The container or content item</param>
        public Address(object cont)
            : this()
        {
            var addressProps = cont.GetType().GetProperties()
                               .Select(pi => new { pi, attr = pi.GetCustomAttribute <AddressComponentAttribute>() })
                               .Where(pii => pii.attr != null)
                               .ToList();

            if (addressProps.Any(ap => ap.attr.UsePath))
            {
                LoadPath((string)addressProps.First(ap => ap.attr.UsePath).pi.GetValue(cont));
            }
            else
            {
                addressProps.Do(pii => this.Add(
                                    pii.attr.RouteKey ?? ("_" + pii.pi.Name),
                                    pii.pi.GetValue(cont)));

                if (this.Count == 0)
                {
                    var keyPi = cont.GetType().GetProperties()
                                .FirstOrDefault(pi => pi.GetCustomAttribute <KeyAttribute>() != null);
                    if (keyPi != null)
                    {
                        this.Add("_id", keyPi.GetValue(cont).ToString());
                    }
                }
            }

            this.Type = Collator.GetContentType(cont);
        }
예제 #2
0
파일: ItemId.cs 프로젝트: slamj1/lyniconanc
 /// <summary>
 /// Constructs an ItemId from an unspecified object which can be a container, a content class or a summary
 /// </summary>
 /// <param name="coll">The collator for the system in which to create this itemid</param>
 /// <param name="o">The unspecified object</param>
 public ItemId(Collator coll, object o)
 {
     if (o is IContentContainer)
     {
         this.Type = Collator.GetContentType(o);
         this.Id   = coll.GetIdProperty(o.GetType().UnproxiedType()).GetValue(o);
     }
     else if (o is Summary)
     {
         this.Type = ((Summary)o).Type;
         this.Id   = ((Summary)o).Id;
     }
     else
     {
         var container = coll.GetContainer(o);
         this.Type = Collator.GetContentType(container);
         this.Id   = coll.GetIdProperty(container.GetType().UnproxiedType()).GetValue(container);
     }
 }
예제 #3
0
파일: ItemId.cs 프로젝트: slamj1/lyniconanc
 /// <summary>
 /// Construct an ItemId by extracting it from a container
 /// </summary>
 /// <param name="coll">The collator from the system for which we are determining the itemid</param>
 /// <param name="container">The container</param>
 public ItemId(Collator coll, IContentContainer container)
     : this(Collator.GetContentType(container), coll.GetIdProperty(container.GetType().UnproxiedType()).GetValue(container))
 {
 }
예제 #4
0
파일: ItemId.cs 프로젝트: slamj1/lyniconanc
 /// <summary>
 /// Construct an ItemId by extracting it from a container, using the primary Lynicon system for this
 /// </summary>
 /// <param name="container">The container</param>
 public ItemId(IContentContainer container)
     : this(Collator.GetContentType(container), Collator.Instance.GetIdProperty(container.GetType().UnproxiedType()).GetValue(container))
 {
 }
예제 #5
0
 /// <summary>
 /// Constructs an address by extracting it from a container or a content item where AddressComponent attributes were
 /// used to map content fields to the address
 /// </summary>
 /// <param name="cont">The container or content item</param>
 public Address(object cont)
     : base(FromContainer(cont))
 {
     this.Type = Collator.GetContentType(cont);
 }