Exemple #1
0
        private string ExtractField(Field field, ISelectable item, Selectable root, int index)
        {
            var selector = field?.ToSelector();

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

            object value;

            if (selector is EnvironmentSelector environmentSelector)
            {
                switch (environmentSelector.Field)
                {
                case EnviromentFields.Index:
                {
                    value = index;
                    break;
                }

                default:
                {
                    value = root.Environment(environmentSelector.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.Length > 0)
            {
                foreach (var formatter in field.Formatters)
                {
#if DEBUG
                    try
                    {
#endif
                    value = formatter.Format(value);
#if DEBUG
                }
                catch (Exception e)
                {
                    Debugger.Log(0, "ERROR", $"ModelExtractor execute formatter failed: {e}");
                }
#endif
                }
            }

            return(value?.ToString());
        }