Nustache.Core.RenderContext.GetValue C# (CSharp) Method

GetValue() public method

public GetValue ( string path ) : object
path string
return object
        public object GetValue(string path)
        {
            if (path == ".")
            {
                object peekedObject = _dataStack.Peek();
                if (peekedObject as XmlElement != null)
                {
                    return ((XmlElement)peekedObject).InnerText;
                }
                return peekedObject;
            }

            foreach (var data in _dataStack)
            {
                if (data != null)
                {
                    bool partialMatch;
                    var value = GetValueFromPath(data, path, out partialMatch);

                    if (partialMatch) break;

                    if (!ReferenceEquals(value, ValueGetter.NoValue))
                    {
                        if (value is string)
                        {
                            var valueAsString = (string)value;
                            if (string.IsNullOrEmpty(valueAsString) && _renderContextBehaviour.RaiseExceptionOnEmptyStringValue)
                            {
                                throw new NustacheEmptyStringException(
                                    string.Format("Path : {0} is an empty string, RaiseExceptionOnEmptyStringValue : true.", path));
                            }
                        }
                        return value;
                    }
                }
            }

            string name;
            IList<object> arguments;
            IDictionary<string, object> options;

            Helpers.Parse(this, path, out name, out arguments, out options);

            if (Helpers.Contains(name))
            {
                var helper = Helpers.Get(name);

                return (HelperProxy)((fn, inverse) => helper(this, arguments, options, fn, inverse));
            }

            if (_renderContextBehaviour.RaiseExceptionOnDataContextMiss)
            {
                throw new NustacheDataContextMissException(string.Format("Path : {0} is undefined, RaiseExceptionOnDataContextMiss : true.", path));
            }

            return null;
        }

Usage Example

示例#1
1
        public override void Render(RenderContext context)
        {
            object value = context.GetValue(_name);

            if (value != null)
            {
                context.Write(value.ToString());
            }
        }
All Usage Examples Of Nustache.Core.RenderContext::GetValue