diff --git a/Extensions/CommonExtensions.cs b/Extensions/CommonExtensions.cs index 8664ce5..4f29a0f 100644 --- a/Extensions/CommonExtensions.cs +++ b/Extensions/CommonExtensions.cs @@ -1817,6 +1817,60 @@ namespace xCommons.Extensions } #endregion + // + #region Dictionary Extensions ... + /// + /// Converts to Meta Data Representation ... + /// + /// + /// + public static Dictionary AsMetadat(this string source) + { + // + // Validate ... + if (source.IsNullOrEmpty()) + { + return []; + } + + // + // JSON is expected to be like: [0.12, 0.34, ...] ... + var result = source.FromJSON>(); + if (!result.HasChild()) + { + result = []; + } + + // + return result; + } + + /// + /// Safe Metadata Reader ... + /// + /// + /// + /// + public static string GetMetadata( + this IDictionary source, + string key + ) + { + // + var result = string.Empty; + + // + if (!source.IsNullOrDefault() && + source.TryGetValue(key, out result)) + { + return result; + } + + // + return result; + } + #endregion + // #region StringExtensions for Identity Server ... public static string EnsureTrailingSlash(this string input)