protected virtual void BuildWithCustom(string prefixKey, IDictionary<string, object> invocationContext, string customKey, StringBuilder key)
{
if (invocationContext.ContainsKey(customKey))
{
var customValue = invocationContext[customKey];
var code = customValue == null
? "null"
: _hashCodeGeneratorProvider.GetForType(customValue.GetType()).GetCode(customValue);
key.Append($" {prefixKey}:{code}");
}
else
{
var indexOfDot = customKey.IndexOf(".", StringComparison.Ordinal);
if (indexOfDot > 0)
{
var prefix = customKey.Substring(0, indexOfDot);
var fieldName = customKey.Substring(indexOfDot + 1);
if (invocationContext.ContainsKey(prefix))
{
var value = invocationContext[prefix];
if (value is IDictionary<string, object>)
{
BuildWithCustom($"{prefixKey}{prefix}.{fieldName}", (IDictionary<string, object>)value, fieldName, key);
}
else
{
indexOfDot = fieldName.IndexOf(".", StringComparison.Ordinal);
try
{
if (indexOfDot < 0) // this should be a propertyName
{
var pInfo = value.GetType().GetProperty(fieldName);
var customValue = pInfo.GetValue(value, null);
BuildWithCustom($"{prefixKey}{prefix}.{fieldName}", new Dictionary<string, object> {{fieldName, customValue}}, fieldName, key);
}
else // Still property chain
{
var prefix2 = fieldName.Substring(0, indexOfDot);
var pInfo = value.GetType().GetProperty(prefix2);
var customValue = pInfo.GetValue(value, null);
BuildWithCustom($"{prefixKey}{prefix}.", new Dictionary<string, object> { { prefix2, customValue } }, fieldName, key);
}
}
catch
{
// Ignore, probably the original customField has more than 1 dot which is not supported or the field after dot not found
}
}
}
}
}
}