private ConfirmationMatcher(IMatchingStrategy matchingStrategy, string consumerName, string description) { this.matchingStrategy = matchingStrategy; this.consumerName = consumerName; this.description = description; this.Timeout = TimeSpan.Zero; }
private void CreateMapping(IMatchingStrategy <string> matching, Dictionary <string, PropertyInfo> sourcePropertyLookup, PropertyInfo target) { var targetName = matching.GetLookup(target); if (sourcePropertyLookup.ContainsKey(targetName) && sourcePropertyLookup[targetName].PropertyType == target.PropertyType) { AddMapping(CreateMapping(sourcePropertyLookup[targetName], target)); } }
public SpecificationMatcherTests() { var equalZero = new Specification <int>(v => v == 0); var equalTwo = new Specification <int>(v => v == 2); var greaterThanOne = new Specification <int>(v => v > 1); var builder = ImmutableDictionary.CreateBuilder <ISpecification <int>, IMatchingHandler <int, List <string> > >(); builder.Add(equalZero, new SpecHandler1()); builder.Add(equalTwo, new SpecHandler2()); builder.Add(greaterThanOne, new SpecHandler3()); _firstMatchStrategy = new SpecificationMatcher <int, List <string> >(builder.ToImmutable(), true); _allMatchStrategy = new SpecificationMatcher <int, List <string> >(builder.ToImmutable()); }
protected override void CreateMappings(Type sourceType, Type targetType, IMatchingStrategy <string> matching) { var sourceProperties = sourceType.GetAccessiblePublicInstanceProperties(); var targetProperties = targetType.GetAccessiblePublicInstanceProperties(); var sourcePropertyLookup = new Dictionary <string, PropertyInfo>(); foreach (var source in sourceProperties) { sourcePropertyLookup.Add(matching.GetLookup(source), source); } foreach (var target in targetProperties) { CreateMapping(matching, sourcePropertyLookup, target); } }
protected override void CreateMappings(string source, Type targetType, IMatchingStrategy <int> matching) { int fieldCount = source.Split(FieldDelimiter).Length; var targetProperties = targetType.GetAccessiblePublicInstanceProperties(); foreach (var target in targetProperties) { for (int i = 1; i < (fieldCount + 1); i++) { if (matching.IsMatch(target, i)) { AddMapping(CreateMapping(i, target)); break; } } } }
protected override void CreateMappings(XDocument source, Type targetType, IMatchingStrategy <string> matching) { var objects = new List <XObject>(); var nodes = (from node in source.Root.DescendantNodesAndSelf() where node.NodeType == XmlNodeType.Element select node as XObject); foreach (var node in nodes) { objects.Add(node); objects.AddRange(from attr in ((XElement)node).Attributes() select attr as XObject); } var targetProperties = targetType.GetAccessiblePublicInstanceProperties(); foreach (var target in targetProperties) { foreach (XObject obj in objects) { XName name = null; XElement element = obj as XElement; if (element != null) { name = element.Name; } else { XAttribute attribute = obj as XAttribute; name = attribute.Name; } if (matching.IsMatch(target, name.LocalName)) { AddMapping(CreateMapping(obj, target)); break; } } } }
protected override void CreateMappings(IDataReader source, Type targetType, IMatchingStrategy <string> matching) { List <string> columnNames = new List <string>(source.FieldCount); for (int i = 0; i < source.FieldCount; i++) { columnNames.Add(source.GetName(i)); } var targetProperties = targetType.GetAccessiblePublicInstanceProperties(); foreach (var target in targetProperties) { foreach (string columnName in columnNames) { if (matching.IsMatch(target, columnName)) { AddMapping(CreateMapping(columnName, target)); break; } } } }
/// <summary> /// Override in inheriting classes to create all the mappings for the target /// </summary> /// <param name="source"></param> /// <param name="targetType"></param> /// <param name="matching"></param> protected abstract void CreateMappings(TSource source, Type targetType, IMatchingStrategy <TMatchingLookup> matching);
/// <summary> /// Returns all the mappings for the target /// </summary> /// <param name="sourceType"></param> /// <param name="targetType"></param> /// <param name="matching"></param> /// <param name="autoMapMissingTargets"></param> /// <returns></returns> public List <IPropertyMapping> GetMappings(object sourceType, Type targetType, IMatchingStrategy <TMatchingLookup> matching, bool autoMapMissingTargets) { if (autoMapMissingTargets && !GeneratedMappings) { CreateMappings(GetSource(sourceType), targetType, matching); GeneratedMappings = true; } return(PropertyMap); }
public List <IPropertyMapping> GetMappings(object source, Type targetType, IMatchingStrategy <string> matching, bool autoMapMissingTargets) { return(new List <IPropertyMapping>()); }
public CompoundInterceptor(IMatchingStrategy matcher, params IInterceptionStrategy[] interceptors) { this.interceptors = interceptors; this.matcher = matcher; }