本文整理汇总了C#中NancyContext.LocalHalConfig方法的典型用法代码示例。如果您正苦于以下问题:C# NancyContext.LocalHalConfig方法的具体用法?C# NancyContext.LocalHalConfig怎么用?C# NancyContext.LocalHalConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NancyContext
的用法示例。
在下文中一共展示了NancyContext.LocalHalConfig方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildHypermedia
private dynamic BuildHypermedia(object model, NancyContext context)
{
if (model == null) return null;
if (model is IEnumerable)
{
//how to handle a collection at the root resource level?
return ((IEnumerable)model).Cast<object>().Select(x => BuildHypermedia(x, context));
}
IDictionary<string, object> halModel = model.ToDynamic();
var globalTypeConfig = configuration.GetTypeConfiguration(model.GetType());
var localTypeConfig = context.LocalHalConfig().GetTypeConfiguration(model.GetType());
var typeConfig = new AggregatingHalTypeConfiguration(new List<IHalTypeConfiguration> { globalTypeConfig, localTypeConfig });
var links = typeConfig.LinksFor(model, context).ToArray();
if (links.Any())
halModel["_links"] = links.GroupBy(l => l.Rel).ToDictionary(grp => grp.Key, grp => BuildDynamicLinksOrLink(grp));
var embeddedResources = typeConfig.EmbedsFor(model, context).ToArray();
if (embeddedResources.Any())
{
// Remove original objects from the model (if they exist)
foreach (var embedded in embeddedResources)
halModel.Remove(embedded.OriginalPropertyName);
halModel["_embedded"] = embeddedResources.ToDictionary(info => info.Rel, info => BuildHypermedia(info.GetEmbeddedResource(model), context));
}
var ignoredProperties = typeConfig.Ignored().ToArray();
if (ignoredProperties.Any())
{
//remove ignored properties from the output
foreach (var ignored in ignoredProperties) halModel.Remove(ignored);
}
return halModel;
}