当前位置: 首页>>代码示例>>C#>>正文


C# IEntity.GetDraft方法代码示例

本文整理汇总了C#中IEntity.GetDraft方法的典型用法代码示例。如果您正苦于以下问题:C# IEntity.GetDraft方法的具体用法?C# IEntity.GetDraft怎么用?C# IEntity.GetDraft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEntity的用法示例。


在下文中一共展示了IEntity.GetDraft方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDictionaryFromEntity

        /// <summary>
        /// Convert an entity into a lightweight dictionary, ready to serialize
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public virtual Dictionary<string, object> GetDictionaryFromEntity(IEntity entity, string language)
        {
            var lngs = new[] {language};
            // Convert Entity to dictionary
            // If the value is a relationship, then give those too, but only Title and Id
            var entityValues = (from d in entity.Attributes select d.Value).ToDictionary(k => k.Name, v =>
            {
                var value = entity.GetBestValue(v.Name, lngs, true);
                if (v.Type == "Entity" && value is Data.EntityRelationship)
                    return ((Data.EntityRelationship) value).Select(p => new
                    {
                        Id = p?.EntityId,
                        Title = p?.GetBestValue("EntityTitle", lngs)?.ToString()
                    }).ToList();
                return value;

            }, StringComparer.OrdinalIgnoreCase);

            // Add Id and Title
            // ...only if these are not already existing with this name in the entity itself as an internal value
            if (entityValues.ContainsKey("Id")) entityValues.Remove("Id");
            entityValues.Add("Id", entity.EntityId);

            if (IncludeGuid)
            {
                if (entityValues.ContainsKey("Guid")) entityValues.Remove("Guid");
                entityValues.Add("Guid", entity.EntityGuid);
            }

            if (IncludePublishingInfo)
            {
                entityValues.Add("RepositoryId", entity.RepositoryId);
                entityValues.Add("IsPublished", entity.IsPublished);
                if (entity.IsPublished && entity.GetDraft() != null)
                {
                    // do a check if there was a field called Published, which we must remove for this to work
                    if (entityValues.ContainsKey(Constants.DraftEntityField))
                        entityValues.Remove(Constants.DraftEntityField);
                    entityValues.Add(Constants.DraftEntityField, new
                    {
                        entity.GetDraft().RepositoryId,
                    });
                }
                if (!entity.IsPublished & entity.GetPublished() != null)
                {
                    // do a check if there was a field called Published, which we must remove for this to work
                    if (entityValues.ContainsKey(Constants.PublishedEntityField))
                        entityValues.Remove(Constants.PublishedEntityField);
                    entityValues.Add(Constants.PublishedEntityField, new
                    {
                        entity.GetPublished().RepositoryId,
                    });
                }
            }

            if (IncludeMetadata)
            {
                if(entity.Metadata.HasMetadata)
                    entityValues.Add("Metadata", entity.Metadata);
            }

            if (!entityValues.ContainsKey("Title"))
                try // there are strange cases where the title is missing, then just ignore this
                {
                    entityValues.Add("Title", entity.GetBestValue("EntityTitle", lngs, true));
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch
                {
                }

            return entityValues;
        }
开发者ID:2sic,项目名称:eav-server,代码行数:79,代码来源:Serializer.cs


注:本文中的IEntity.GetDraft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。