using Umbraco.Cms.Core.Mapping; namespace Umbraco.Extensions { /// /// Provides extension methods for the class. /// public static class MapperContextExtensions { private const string CultureKey = "Map.Culture"; private const string SegmentKey = "Map.Segment"; private const string IncludedPropertiesKey = "Map.IncludedProperties"; /// /// Gets the context culture. /// public static string GetCulture(this MapperContext context) { return context.HasItems && context.Items.TryGetValue(CultureKey, out var obj) && obj is string s ? s : null; } /// /// Gets the context segment. /// public static string GetSegment(this MapperContext context) { return context.HasItems && context.Items.TryGetValue(SegmentKey, out var obj) && obj is string s ? s : null; } /// /// Sets a context culture. /// public static void SetCulture(this MapperContext context, string culture) { context.Items[CultureKey] = culture; } /// /// Sets a context segment. /// public static void SetSegment(this MapperContext context, string segment) { context.Items[SegmentKey] = segment; } /// /// Get included properties. /// public static string[] GetIncludedProperties(this MapperContext context) { return context.HasItems && context.Items.TryGetValue(IncludedPropertiesKey, out var obj) && obj is string[] s ? s : null; } /// /// Sets included properties. /// public static void SetIncludedProperties(this MapperContext context, string[] properties) { context.Items[IncludedPropertiesKey] = properties; } } }