本文整理汇总了C#中ContentItem.Get方法的典型用法代码示例。如果您正苦于以下问题:C# ContentItem.Get方法的具体用法?C# ContentItem.Get怎么用?C# ContentItem.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentItem
的用法示例。
在下文中一共展示了ContentItem.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildDisplayAsync
public async Task BuildDisplayAsync(ContentItem contentItem, BuildDisplayContext context)
{
// Optimized implementation for display
// For each field on the content item, invoke all IContentFieldDisplayDriver instances
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);
if(contentTypeDefinition == null)
{
return;
}
var partInfos = _contentPartDrivers.Select(x => x.GetPartInfo()).ToDictionary(x => x.PartName);
foreach (var contentTypePartDefinition in contentTypeDefinition.Parts)
{
var partName = contentTypePartDefinition.PartDefinition.Name;
var partType = partInfos.ContainsKey(partName) ? partInfos[partName].Factory(contentTypePartDefinition).GetType() : null;
var part = contentItem.Get(partType ?? typeof(ContentPart), partName) as ContentPart;
foreach (var contentPartFieldDefinition in contentTypePartDefinition.PartDefinition.Fields)
{
var fieldName = contentPartFieldDefinition.Name;
foreach (var displayDriver in _displayDrivers)
{
try
{
var result = await displayDriver.BuildDisplayAsync(fieldName, part, contentPartFieldDefinition, context);
if (result != null)
{
result.Apply(context);
}
}
catch (Exception ex)
{
InvokeExtensions.HandleException(ex, Logger, displayDriver.GetType().Name, "BuildDisplayAsync");
}
}
}
}
}
示例2: Process
public Task Process(ContentItem contentItem, Func<ContentPart, string, Task> action)
{
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);
if (contentTypeDefinition == null)
return Task.CompletedTask;
foreach (var typePartDefinition in contentTypeDefinition.Parts)
{
// Abort if there are not fields in this part
if (!typePartDefinition.PartDefinition.Fields.Any())
{
continue;
}
var partName = typePartDefinition.PartDefinition.Name;
ContentPartInfo partInfo;
_partInfos.TryGetValue(partName, out partInfo);
ContentPart part = partInfo != null
? partInfo.Factory(typePartDefinition)
: new ContentPart();
part = contentItem.Get(part.GetType(), partName) as ContentPart;
if(part == null)
{
return Task.CompletedTask;
}
foreach (var partFieldDefinition in typePartDefinition.PartDefinition.Fields)
{
var fieldName = partFieldDefinition.Name;
return action(part, fieldName);
}
}
return Task.CompletedTask;
}