public DatagridResult(IEasyuiList <T> rows)
        {
            var enumerable = rows.AsEnumerable() as T[] ?? rows.AsEnumerable().ToArray();

            Rows  = enumerable;
            Total = enumerable.Count();
        }
Beispiel #2
0
        ComboboxResult IComboboxResultFactory.Build <T>(IEasyuiList <T> items)
        {
            var enumerable = items.AsEnumerable() as T[] ?? items?.AsEnumerable()?.ToArray();

            if (!enumerable?.Any() == true)
            {
                return(new ComboboxResult(Enumerable.Empty <ComboboxItem>()));
            }
            var item          = enumerable.First();
            var valueResolver = _comboboxValueResolvers.FirstOrDefault(x => x.CanResolve(item));

            if (valueResolver == null)
            {
                throw new AvaliableResolverNotFoundException();
            }
            var textResolver = _comboboxTextResolvers.FirstOrDefault(x => x.CanResolve(item));

            if (textResolver == null)
            {
                throw new AvaliableResolverNotFoundException();
            }
            var re = enumerable.Select(x => new ComboboxItem
            {
                Text  = textResolver.ResolveText(x),
                Value = valueResolver.ResolveValue(x),
            }).ToList();

            return(new ComboboxResult(re));
        }
        public static ComboboxResult ToComboboxResult <T>(this IEasyuiList <T> source,
                                                          ComboboxResultBuildOptions <T> buildOptions)
        {
            var re = new ComboboxResult(source.AsEnumerable().Select(x => new ComboboxItem
            {
                Text  = buildOptions.TextFunc(x),
                Value = buildOptions.ValueFunc(x),
            }));

            return(re);
        }
Beispiel #4
0
        TreeResult <T> ITreeResultFactory.Build <T>(IEasyuiList <T> items, EasyuiTreeBuildOptions <T> buildOptions)
        {
            var type    = typeof(T);
            var builder = TreeBuilderCache.GetOrAdd(type, type1 =>
            {
                var r           = new TreePropertyResolver();
                var properInfos = type.GetRuntimeProperties().ToArray();
                r.IdResolver    =
                    properInfos.FirstOrDefault(
                        x => x.CustomAttributes.Any(a => a.AttributeType == typeof(EasyuiTreeIdAttribute)));
                r.TextResolver =
                    properInfos.FirstOrDefault(
                        x => x.CustomAttributes.Any(a => a.AttributeType == typeof(EasyuiTreeTextAttribute)));
                return(r);
            });
            var re = new TreeResult <T>(items.AsEnumerable().Select(x =>
            {
                var treeNode = new TreeNode <T>(x, null, null)
                {
                    Attributes = buildOptions.AttributesFunc?.Invoke(x),
                };
                if (buildOptions.IdFunc == null && builder.IdResolver == null)
                {
                    throw new ArgumentNullException(nameof(buildOptions.IdFunc));
                }
                treeNode.Id = buildOptions.IdFunc == null
                    ? builder.IdResolver.GetValue(x)?.ToString()
                    : buildOptions.IdFunc(x);
                if (buildOptions.TextFunc == null && builder.TextResolver == null)
                {
                    throw new ArgumentNullException(nameof(buildOptions.TextFunc));
                }
                treeNode.Text = buildOptions.TextFunc == null
                    ? builder.TextResolver.GetValue(x)?.ToString()
                    : buildOptions.TextFunc(x);
                return(treeNode);
            }));

            return(re);
        }