/// <summary> /// Creates a lightweight DD4T Component that contains enough information such that the semantic model builder can cope and build a strongly typed model from it. /// </summary> /// <param name="componentMeta">A <see cref="DD4T.ContentModel.IComponentMeta"/> instance obtained from CD API.</param> /// <returns>A DD4T Component.</returns> private static IComponent CreateComponent(IComponentMeta componentMeta) { Component component = new Component { Id = $"tcm:{componentMeta.PublicationId}-{componentMeta.Id}", LastPublishedDate = componentMeta.LastPublicationDate, RevisionDate = componentMeta.ModificationDate, Schema = new Schema { PublicationId = componentMeta.PublicationId.ToString(), Id = $"tcm:{componentMeta.PublicationId}-{componentMeta.SchemaId}" }, MetadataFields = new FieldSet() }; FieldSet metadataFields = new FieldSet(); component.MetadataFields.Add("standardMeta", new Field { EmbeddedValues = new List <FieldSet> { metadataFields } }); foreach (DictionaryEntry de in componentMeta.CustomMeta.NameValues) { object v = ((NameValuePair)de.Value).Value; if (v == null) { continue; } string k = de.Key.ToString(); metadataFields.Add(k, new Field { Name = k, Values = new List <string> { v.ToString() } }); } // The semantic mapping requires that some metadata fields exist. This may not be the case so we map some component meta properties onto them // if they don't exist. if (!metadataFields.ContainsKey("dateCreated")) { metadataFields.Add("dateCreated", new Field { Name = "dateCreated", DateTimeValues = new List <DateTime> { componentMeta.LastPublicationDate } }); } if (!metadataFields.ContainsKey("name")) { metadataFields.Add("name", new Field { Name = "name", Values = new List <string> { componentMeta.Title } }); } return(component); }