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 object ResolveParameters(BindingContext context, HashParametersExpression hpex) { var parameters = new HashParameterDictionary(); foreach (var parameter in hpex.Parameters) { var path = parameter.Value as PathExpression; parameters.Add(parameter.Key, path != null ? ResolvePath(context, path.Path) : parameter.Value); } return(parameters); }
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; } }
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 object ResolveParameters(BindingContext context, HashParametersExpression hpex) { var parameters = new HashParameterDictionary(); foreach (var parameter in hpex.Parameters) { var path = parameter.Value as PathExpression; if (path != null) { parameters.Add(parameter.Key, ResolvePath(context, path.Path)); } else { parameters.Add(parameter.Key, parameter.Value); } } return parameters; }
private static LogLevel GetLogLevel(HashParameterDictionary parameters) { return(parameters?.GetConvertedValue("level", o => Enum.TryParse(o.ToString(), true, out LogLevel loglevel) ? loglevel : DefaultLogLevel, DefaultLogLevel) ?? DefaultLogLevel); }