示例#1
0
        private IEnumerable <FieldDescriptor> BuildListWithFieldsToShow(string fieldString)
        {
            var fieldList  = new List <FieldDescriptor>();
            var fieldNames = new ListString(fieldString).ToArray();

            if (fieldNames.Any())
            {
                IncludePatterns =
                    fieldNames
                    .Where(name => !name.StartsWith("-"))
                    .Select(
                        name =>
                        new WildcardPattern(name, WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant))
                    .ToList();
                ExcludePatterns =
                    fieldNames
                    .Where(name => name.StartsWith("-"))
                    .Select(
                        name =>
                        new WildcardPattern(name.Substring(1),
                                            WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant))
                    .ToList();
            }
            var currentItem = CurrentItem;

            currentItem.Fields.ReadAll();
            var template =
                TemplateManager.GetTemplate(Settings.DefaultBaseTemplate,
                                            currentItem.Database);

            FieldCollection fields = new FieldCollection(CurrentItem);

            fields.ReadAll();
            fields.Sort();

            foreach (Field field in fields)
            {
                //if not including standard field and it's standard, skip it.
                if (!IncludeStandardFields && template.ContainsField(field.ID))
                {
                    continue;
                }

                var name          = field.Name;
                var wildcardMatch = IncludePatterns.Any(pattern => pattern.IsMatch(name));
                if (!wildcardMatch)
                {
                    continue;
                }
                if (ExcludePatterns.Any(pattern => pattern.IsMatch(name)))
                {
                    wildcardMatch = false;
                }
                if (wildcardMatch)
                {
                    fieldList.Add(new FieldDescriptor(currentItem, field.Name));
                }
            }
            return(fieldList);
        }
示例#2
0
        public static IEnumerable <Item> GetItems(this Item item, string fieldID)
        {
            Field field = item.Fields[new ID(fieldID)];

            Assert.IsNotNull(field, "item does not have field: " + fieldID);
            ListString itemIds = new ListString(field.Value);

            if (!itemIds.Any())
            {
                return(Enumerable.Empty <Item>());
            }
            return(itemIds.Where(id => ID.IsID(id)).Select(id => item.Database.GetItem(id)));
        }
示例#3
0
        private IEnumerable<FieldDescriptor> BuildListWithFieldsToShow(string fieldString)
        {
            var fieldList = new List<FieldDescriptor>();
            var fieldNames = new ListString(fieldString).ToArray();

            if (fieldNames.Any())
            {
                IncludePatterns =
                    fieldNames
                        .Where(name => !name.StartsWith("-"))
                        .Select(
                            name =>
                                new WildcardPattern(name, WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant))
                        .ToList();
                ExcludePatterns =
                    fieldNames
                        .Where(name => name.StartsWith("-"))
                        .Select(
                            name =>
                                new WildcardPattern(name.Substring(1),
                                    WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant))
                        .ToList();
            }
            var currentItem = CurrentItem;
            currentItem.Fields.ReadAll();
            var template =
                TemplateManager.GetTemplate(Settings.DefaultBaseTemplate,
                    currentItem.Database);

            foreach (Field field in currentItem.Fields)
            {
                //if not including standard field and it's standard, skip it.
                if (!IncludeStandardFields && template.ContainsField(field.ID))
                {
                    continue;
                }

                var name = field.Name;
                var wildcardMatch = IncludePatterns.Any(pattern => pattern.IsMatch(name));
                if (!wildcardMatch)
                {
                    continue;
                }
                if (ExcludePatterns.Any(pattern => pattern.IsMatch(name)))
                {
                    wildcardMatch = false;
                }
                if (wildcardMatch)
                {
                    fieldList.Add(new FieldDescriptor(currentItem, field.Name));
                }
            }
            return fieldList;
        }