public void Clear_field_path() { var aw = new AdventureWorks(); var path = new FieldPath( aw.SalesOrderDetails["ProductID"], aw.Products["ProductCategoryID"], aw.ProductCategory.DefaultField); path.Clear(); Assert.AreEqual(0, path.Count); }
/// <summary> /// Parse text containing placeholders for fields delimited by bracket. /// The first stop delimits the subject.field, subsequent stops traverse relationships. /// For example: /// [Products.Name] is the "Products" subject, field "Name" /// [Products.ProductCategoryID.Name] is the "Products" subject, field "ProductCategoryID" which is a RelationField to subject "Product Category" with a field "Name". /// </summary> /// <param name="subject"></param> /// <param name="texts"></param> /// <returns></returns> public virtual Dictionary <string, IFieldPath> Parse(IConfiguration config, params string[] texts) { var fields = new Dictionary <string, IFieldPath>(); foreach (var t in texts) { var matches = Regex.Matches(t, @"\[((?<subject>[^\]\.]+)(\.([^\]\.]+))+)\]"); foreach (Match m in matches) { // represent the entire path as the key to the dictionary if (!fields.ContainsKey(m.Groups[1].Value)) { // now create the FieldPath based on the Regex var path = new FieldPath(); var subject = config[m.Groups["subject"].Value]; if (subject != null) { foreach (Capture capture in m.Groups[3].Captures) { var field = subject[capture.Value]; if (field == null) { path.Clear(); break; } path.Add(field); if (field is IRelationField) { subject = ((IRelationField)field).RelatedSubject; } } if (path.Count > 0) { fields.Add(m.Groups[0].Value, path); } } } } } return(fields); }