Пример #1
0
 private static void Iterate(
     ObjectEnumeratorBindingContext context,
     IDynamicMetaObjectProvider target,
     Action <TextWriter, object> template,
     Action <TextWriter, object> ifEmpty)
 {
     if (HandlebarsUtils.IsTruthy(target))
     {
         context.Index = 0;
         var meta = target.GetMetaObject(Expression.Constant(target));
         foreach (var name in meta.GetDynamicMemberNames())
         {
             context.Key = name;
             var value = GetProperty(target, name);
             context.First = (context.Index == 0);
             template(context.TextWriter, value);
             context.Index++;
         }
         if (context.Index == 0)
         {
             ifEmpty(context.TextWriter, context.Value);
         }
     }
     else
     {
         ifEmpty(context.TextWriter, context.Value);
     }
 }
Пример #2
0
 private static void Iterate(
     ObjectEnumeratorBindingContext context,
     IEnumerable target,
     Action <TextWriter, object> template,
     Action <TextWriter, object> ifEmpty)
 {
     if (HandlebarsUtils.IsTruthy(target))
     {
         context.Index = 0;
         var keysProperty = target.GetType().GetProperty("Keys");
         if (keysProperty != null)
         {
             var keys = keysProperty.GetGetMethod().Invoke(target, null) as IEnumerable <object>;
             if (keys != null)
             {
                 foreach (var key in keys)
                 {
                     context.Key = key.ToString();
                     var value = target.GetType().GetMethod("get_Item").Invoke(target, new[] { key });
                     context.First = (context.Index == 0);
                     template(context.TextWriter, value);
                     context.Index++;
                 }
             }
         }
         if (context.Index == 0)
         {
             ifEmpty(context.TextWriter, context.Value);
         }
     }
     else
     {
         ifEmpty(context.TextWriter, context.Value);
     }
 }
Пример #3
0
 private static void Iterate(
     ObjectEnumeratorBindingContext context,
     object target,
     Action <TextWriter, object> template,
     Action <TextWriter, object> ifEmpty)
 {
     if (HandlebarsUtils.IsTruthy(target))
     {
         context.Index = 0;
         foreach (MemberInfo member in target.GetType()
                  .GetProperties(BindingFlags.Instance | BindingFlags.Public).OfType <MemberInfo>()
                  .Concat(
                      target.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
                      ))
         {
             context.Key = member.Name;
             var value = AccessMember(target, member);
             context.First = (context.Index == 0);
             template(context.TextWriter, value);
             context.Index++;
         }
         if (context.Index == 0)
         {
             ifEmpty(context.TextWriter, context.Value);
         }
     }
     else
     {
         ifEmpty(context.TextWriter, context.Value);
     }
 }
Пример #4
0
        private static void Iterate(
            ObjectEnumeratorBindingContext context,
            object target,
            Action <TextWriter, object> template,
            Action <TextWriter, object> ifEmpty)
        {
            if (HandlebarsUtils.IsTruthy(target))
            {
                context.Index = 0;
                var targetType = target.GetType();
                var properties = targetType.GetProperties(BindingFlags.Instance | BindingFlags.Public).OfType <MemberInfo>();
                var fields     = targetType.GetFields(BindingFlags.Public | BindingFlags.Instance);
                foreach (var enumerableValue in new ExtendedEnumerable <MemberInfo>(properties.Concat(fields)))
                {
                    var member = enumerableValue.Value;
                    context.Key = member.Name;
                    var value = AccessMember(target, member);
                    context.First = enumerableValue.IsFirst;
                    context.Last  = enumerableValue.IsLast;
                    context.Index = enumerableValue.Index;

                    template(context.TextWriter, value);
                }

                if (context.Index == 0)
                {
                    ifEmpty(context.TextWriter, context.Value);
                }
            }
            else
            {
                ifEmpty(context.TextWriter, context.Value);
            }
        }
Пример #5
0
        private static void Iterate(
            ObjectEnumeratorBindingContext context,
            object target,
            Action <TextWriter, object> template,
            Action <TextWriter, object> ifEmpty)
        {
            bool firstSet = false;

            foreach (MemberInfo member in target.GetType()
                     .GetProperties(BindingFlags.Instance | BindingFlags.Public).OfType <MemberInfo>()
                     .Concat(
                         target.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
                         ))
            {
                context.Key = member.Name;
                var value = AccessMember(target, member);
                if (firstSet == false)
                {
                    context.First = value;
                }
                template(context.TextWriter, value);
            }
            if (firstSet == false)
            {
                ifEmpty(context.TextWriter, context.Value);
            }
        }
Пример #6
0
        private static void Iterate(
            ObjectEnumeratorBindingContext context,
            IEnumerable target,
            Action <TextWriter, object> template,
            Action <TextWriter, object> ifEmpty)
        {
            if (HandlebarsUtils.IsTruthy(target))
            {
                context.Index = 0;
                var targetType = target.GetType();
#if netstandard
                var keysProperty = targetType.GetRuntimeProperty("Keys");
#else
                var keysProperty = targetType.GetProperty("Keys");
#endif
                if (keysProperty != null)
                {
                    var keys = keysProperty.GetGetMethod().Invoke(target, null) as IEnumerable;
                    if (keys != null)
                    {
                        var getItemMethodInfo = targetType.GetMethod("get_Item");
                        var parameters        = new object[1];
                        foreach (var enumerableValue in new ExtendedEnumerable <object>(keys))
                        {
                            var key = parameters[0] = enumerableValue.Value;
                            context.Key = key.ToString();
                            var value = getItemMethodInfo.Invoke(target, parameters);
                            context.First = enumerableValue.IsFirst;
                            context.Last  = enumerableValue.IsLast;
                            context.Index = enumerableValue.Index;

                            template(context.TextWriter, value);
                        }
                    }
                }
                if (context.Index == 0)
                {
                    ifEmpty(context.TextWriter, context.Value);
                }
            }
            else
            {
                ifEmpty(context.TextWriter, context.Value);
            }
        }
Пример #7
0
 private static void Iterate(
     ObjectEnumeratorBindingContext context,
     IDynamicMetaObjectProvider target,
     Action<TextWriter, object> template,
     Action<TextWriter, object> ifEmpty)
 {
     if (HandlebarsUtils.IsTruthy(target))
     {
         context.Index = 0;
         var meta = target.GetMetaObject(Expression.Constant(target));
         foreach (var name in meta.GetDynamicMemberNames())
         {
             context.Key = name;
             var value = GetProperty(target, name);
             context.First = (context.Index == 0);
             template(context.TextWriter, value);
             context.Index++;
         }
         if (context.Index == 0)
         {
             ifEmpty(context.TextWriter, context.Value);
         }
     }
     else
     {
         ifEmpty(context.TextWriter, context.Value);
     }
 }
Пример #8
0
        private static void Iterate(
            ObjectEnumeratorBindingContext context,
            IEnumerable target,
            Action<TextWriter, object> template,
            Action<TextWriter, object> ifEmpty)
        {
            if (HandlebarsUtils.IsTruthy(target))
            {
                context.Index = 0;
#if netstandard
                var keysProperty = target.GetType().GetRuntimeProperty("Keys");
#else
                var keysProperty = target.GetType().GetProperty("Keys");
#endif
                if (keysProperty != null)
                {
                    var keys = keysProperty.GetGetMethod().Invoke(target, null) as IEnumerable;
                    if (keys != null)
                    {
                        foreach (var key in keys)
                        {
                            context.Key = key.ToString();
#if netstandard
                            var value = target.GetType().GetTypeInfo().GetMethod("get_Item").Invoke(target, new[] { key });
#else
                            var value = target.GetType().GetMethod("get_Item").Invoke(target, new[] { key });
#endif
                            context.First = (context.Index == 0);
                            template(context.TextWriter, value);
                            context.Index++;
                        }
                    }
                }
                if (context.Index == 0)
                {
                    ifEmpty(context.TextWriter, context.Value);
                }
            }
            else
            {
                ifEmpty(context.TextWriter, context.Value);
            }
        }
Пример #9
0
        private static void Iterate(
            ObjectEnumeratorBindingContext context,
            object target,
            Action<TextWriter, object> template,
            Action<TextWriter, object> ifEmpty)
        {
            if (HandlebarsUtils.IsTruthy(target))
            {
                context.Index = 0;
#if netstandard
                foreach (MemberInfo member in target.GetType().GetTypeInfo()
#else
                foreach (MemberInfo member in target.GetType()
#endif
                    .GetProperties(BindingFlags.Instance | BindingFlags.Public).OfType<MemberInfo>()
                    .Concat(
#if netstandard
                        target.GetType().GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance)
#else
                        target.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
#endif
                    ))
                {
                    context.Key = member.Name;
                    var value = AccessMember(target, member);
                    context.First = (context.Index == 0);
                    template(context.TextWriter, value);
                    context.Index++;
                }
                if (context.Index == 0)
                {
                    ifEmpty(context.TextWriter, context.Value);
                }
            }
            else
            {
                ifEmpty(context.TextWriter, context.Value);
            }
        }
Пример #10
0
 private static void Iterate(
     ObjectEnumeratorBindingContext context,
     object target,
     Action<TextWriter, object> template,
     Action<TextWriter, object> ifEmpty)
 {
     bool firstSet = false;
     foreach(MemberInfo member in target.GetType()
         .GetProperties(BindingFlags.Instance | BindingFlags.Public).OfType<MemberInfo>()
         .Concat(
             target.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
         ))
     {
         context.Key = member.Name;
         var value = AccessMember(target, member);
         if(firstSet == false)
         {
             context.First = value;
         }
         template(context.TextWriter, value);
     }
     if(firstSet == false)
     {
         ifEmpty(context.TextWriter, context.Value);
     }
 }