示例#1
0
        private string ExtractField(FieldSelector field, ISelectable item, Selectable root, int index)
        {
            if (field == null)
            {
                return(null);
            }

            var selector = field.ToSelector();

            if (selector == null)
            {
                return(null);
            }

            object value;

            if (selector is EnviromentSelector)
            {
                var enviromentSelector = selector as EnviromentSelector;
                switch (enviromentSelector.Field)
                {
                case EnviromentFields.Index:
                {
                    value = index;
                    break;
                }

                default:
                {
                    value = root.Enviroment(enviromentSelector.Field);
                    break;
                }
                }
            }
            else
            {
                value = field.Option == FieldOptions.Count
                                        ? item.SelectList(selector).Nodes().Count().ToString()
                                        : item.Select(selector)?.GetValue(ConvertToValueOption(field.Option));
            }

            if (field.Formatters != null && field.Formatters.Count() > 0)
            {
                foreach (var formatter in field.Formatters)
                {
#if DEBUG
                    try
                    {
#endif
                    value = formatter.Formate(value);
#if DEBUG
                }
                catch (Exception e)
                {
                    Debugger.Log(0, "ERROR", $"ModelExtractor execute formatter failed: {e}");
                }
#endif
                }
            }

            return(value?.ToString());
        }