public override void ModifyObj(TObj obj, string FromText) { var regexPattern = GetRegex(); var regex = new Regex(regexPattern); var match = regex.Match(FromText); if (!match.Success) { throw new InvalidOperationException(String.Format("Could not match regex {0} to input {1}", regexPattern, FromText)); } string capture_name = GetEnumerableGroupCaptureName(); var captures = match.Groups[capture_name].Captures.Cast <Capture>(); IList list = ListFactory(); Trace.WriteLine(String.Format("EnumerablePropertyBuilder.GetRegex(): Processing {0}.{1} - begin", this.TargetMember.DeclaringType.Name, this.TargetMember.Name)); foreach (var capture in captures) { object property_value = capture.Value; Trace.WriteLine(String.Format("EnumerablePropertyBuilder.GetRegex(): Processing {0}.{1} - enumerable match {2} - begin", this.TargetMember.DeclaringType.Name, this.TargetMember.Name, capture.Value)); var modifiers = GetModifiers().Reverse().ToArray(); foreach (var modifier in modifiers) { Trace.WriteLine(String.Format("EnumerablePropertyBuilder.GetRegex(): Processing {0}.{1} - enumerable match {2} ({3}) - applying modifier {4}", this.TargetMember.DeclaringType.Name, this.TargetMember.Name, capture.Value, property_value, modifier)); property_value = modifier.ModifyTargetValue(this.Builder, this.UnderlyingElementType, property_value); } Trace.WriteLine(String.Format("EnumerablePropertyBuilder.GetRegex(): Processing {0}.{1} - enumerable match {2} - completed, result {3}", this.TargetMember.DeclaringType.Name, this.TargetMember.Name, capture.Value, property_value)); list.Add(property_value); } if (MinCount != null && list.Count < (int)MinCount) { throw new InvalidOperationException(String.Format("Expected at least {0} items, but found only {1}", (int)MinCount, list.Count)); } if (MaxCount != null && list.Count > (int)MaxCount) { throw new InvalidOperationException(String.Format("Expected at most {0} items, but found {1}", (int)MaxCount, list.Count)); } Trace.WriteLine(String.Format("EnumerablePropertyBuilder.GetRegex(): Processing {0}.{1} - completed", this.TargetMember.DeclaringType.Name, this.TargetMember.Name)); TargetMember.SetValue(obj, list); }
public virtual void ModifyObj(TObj obj, string FromText) { if (String.IsNullOrWhiteSpace(FromText)) { return; } object property_value = FromText; var modifiers = GetModifiers().Reverse(); foreach (var modifier in modifiers) { property_value = modifier.ModifyTargetValue(this.Builder, this.TargetMember.GetUnderlyingType(), property_value); } TargetMember.SetValue(obj, property_value); }