add Dictionary (MetaData) Extensions ...
This commit is contained in:
@@ -1817,6 +1817,60 @@ namespace xCommons.Extensions
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Dictionary Extensions ...
|
||||
/// <summary>
|
||||
/// Converts to Meta Data Representation ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, string> AsMetadat(this string source)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (source.IsNullOrEmpty())
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
//
|
||||
// JSON is expected to be like: [0.12, 0.34, ...] ...
|
||||
var result = source.FromJSON<Dictionary<string, string>>();
|
||||
if (!result.HasChild())
|
||||
{
|
||||
result = [];
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Safe Metadata Reader ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMetadata(
|
||||
this IDictionary<string, string> 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)
|
||||
|
||||
Reference in New Issue
Block a user