Пример #1
0
        public IEnumerable <object> GetValues(string path)
        {
            object value = GetValue(path);

            if (value == null)
            {
                if (_renderContextBehaviour.RaiseExceptionOnDataContextMiss)
                {
                    throw new NustacheDataContextMissException(string.Format("Path : {0} is undefined, RaiseExceptionOnDataContextMiss : true.", path));
                }
                yield break;
            }
            else if (value is bool)
            {
                if ((bool)value)
                {
                    yield return(value);
                }
            }
            else if (value is string)
            {
                if (!string.IsNullOrEmpty((string)value))
                {
                    yield return(value);
                }
            }
            else if (GenericIDictionaryUtil.IsInstanceOfGenericIDictionary(value))
            {
                if ((value as IEnumerable).GetEnumerator().MoveNext())
                {
                    yield return(value);
                }
            }
            else if (value is IDictionary) // Dictionaries also implement IEnumerable
                                           // so this has to be checked before it.
            {
                if (((IDictionary)value).Count > 0)
                {
                    yield return(value);
                }
            }
            else if (value is IEnumerable)
            {
                foreach (var item in ((IEnumerable)value))
                {
                    yield return(item);
                }
            }
            else
            {
                yield return(value);
            }
        }
Пример #2
0
        public IEnumerable <object> GetValues(string path)
        {
            object value = GetValue(path);

            if (value is bool)
            {
                if ((bool)value)
                {
                    yield return(value);
                }
            }
            else if (value is string)
            {
                if (!string.IsNullOrEmpty((string)value))
                {
                    yield return(value);
                }
            }
            else if (GenericIDictionaryUtil.IsInstanceOfGenericIDictionary(value))
            {
                if ((value as IEnumerable).GetEnumerator().MoveNext())
                {
                    yield return(value);
                }
            }
            else if (value is IDictionary)             // Dictionaries also implement IEnumerable
            // so this has to be checked before it.
            {
                if (((IDictionary)value).Count > 0)
                {
                    yield return(value);
                }
            }
            else if (value is IEnumerable)
            {
                foreach (var item in ((IEnumerable)value))
                {
                    yield return(item);
                }
            }
            else if (value != null)
            {
                yield return(value);
            }
        }