private static bool ProcessSegment(BindingContext context, PathInfo pathInfo, bool isVariable, ChainSegment chainSegment, HashParameterDictionary hashParameters, ref object instance) { instance = ResolveValue(isVariable, context, instance, chainSegment); if (!(instance is UndefinedBindingResult undefined)) { return(true); } if (hashParameters == null || hashParameters.ContainsKey(chainSegment) || context.ParentContext == null) { if (context.Configuration.ThrowOnUnresolvedBindingExpression) { Throw.Undefined(pathInfo, undefined); } return(false); // return instance } instance = ResolveValue(isVariable, context.ParentContext, context.ParentContext.Value, chainSegment); if (!(instance is UndefinedBindingResult result)) { return(true); } if (context.Configuration.ThrowOnUnresolvedBindingExpression) { Throw.Undefined(pathInfo, result); } return(false); // return instance }
private static void PopulateHash(HashParameterDictionary hash, object from) { var descriptor = ObjectDescriptor.Create(from); if (descriptor == ObjectDescriptor.Empty) { return; } var accessor = descriptor.MemberAccessor; var properties = descriptor.GetProperties(descriptor, from); var enumerator = properties.GetEnumerator(); while (enumerator.MoveNext()) { var segment = ChainSegment.Create(enumerator.Current); if (hash.ContainsKey(segment)) { continue; } if (!accessor.TryGetValue(@from, segment, out var value)) { continue; } hash[segment] = value; } }
private static void PopulateHash(HashParameterDictionary hash, object from, ICompiledHandlebarsConfiguration configuration) { var descriptor = HandlebarsDotNet.ObjectDescriptors.ObjectDescriptor.Create(from, configuration.ObjectDescriptorProvider); var accessor = descriptor.MemberAccessor; var properties = descriptor.GetProperties(descriptor, from); var enumerator = properties.GetEnumerator(); while (enumerator.MoveNext()) { var segment = ChainSegment.Create(enumerator.Current); if (hash.ContainsKey(segment)) { continue; } if (!accessor.TryGetValue(@from, segment, out var value)) { continue; } hash[segment] = value; } }