/// <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); }
/// <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); } }
/// <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)) { }
/// <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)) { }
/// <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); }