Exemple #1
0
        public static List <SelectEntry> ParsePropertyNames(string properties, string prefix = "")
        {
            string             pattern = @"((?<complex>[A-Za-z0-9\*]+)\[(?<props>[[A-Za-z0-9,\*]+)\]?)+|(?<simple>\w+)";
            List <SelectEntry> ret     = new List <SelectEntry>();
            MatchCollection    matches = Regex.Matches(properties.Replace(" ", ""), pattern);

            if (matches.Any())
            {
                matches.ToList().ForEach(o =>
                {
                    if (!string.IsNullOrEmpty(o.Groups["simple"].Value))
                    {
                        ret.Add(new SelectEntry()
                        {
                            Property = o.Value
                        });
                    }
                    else
                    {
                        SelectEntry entry = new SelectEntry()
                        {
                            Property = o.Groups["complex"].Value,
                            Childs   = ParsePropertyNames(o.Groups["props"].Value)
                        };
                        ret.Add(entry);
                    }
                });
            }

            return(ret);
        }
        public bool HasProperty(string name)
        {
            string[]    properties = name.Split(".");
            SelectEntry entry      = this;

            if (properties.Count() == 1)
            {
                return(Property.Equals(properties[0], System.StringComparison.InvariantCultureIgnoreCase));
            }
            else
            {
                entry = Childs.Where(o => o.Property == properties[0]).FirstOrDefault();
                return(entry == null ? false : entry.HasProperty(string.Join(".", properties.Skip(1))));
            }
        }
        public string ToSelector()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(this.Property);
            if (this.Childs.Count > 0)
            {
                sb.Append("[");
                for (int i = 0; i < this.Childs.Count; i++)
                {
                    SelectEntry entry = this.Childs[i];
                    if (entry != null)
                    {
                        sb.Append(entry.ToSelector());
                        if (i < this.Childs.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                }
                sb.Append("]");
            }
            return(sb.ToString());
        }
 public virtual Selector AddEntry(SelectEntry entry)
 {
     this.Fields.Add(entry);
     return(this);
 }
 public SelectEntry AddChildProperty(SelectEntry entry)
 {
     Childs.Add(entry);
     return(this);
 }