public static MappingMatcher PrefixSuffixMatcher(string sourcePrefix, string sourceSuffix, string destinationPrefix, string destinationSuffix, MappingMatcherBehaviors matcherBehaviors = MappingMatcherBehaviors.None) { if (string.IsNullOrEmpty(sourcePrefix)) { throw new ArgumentException("Must not be null or empty", nameof(sourcePrefix)); } if (string.IsNullOrEmpty(sourceSuffix)) { throw new ArgumentException("Must not be null or empty", nameof(sourceSuffix)); } if (string.IsNullOrEmpty(destinationPrefix)) { throw new ArgumentException("Must not be null or empty", nameof(destinationPrefix)); } if (string.IsNullOrEmpty(destinationSuffix)) { throw new ArgumentException("Must not be null or empty", nameof(destinationSuffix)); } return((Type sourceType, Type destinationType) => { if (sourceType == destinationType) { return matcherBehaviors.HasFlag(MappingMatcherBehaviors.MatchIdenticalType); } var sourceTypeName = sourceType.ExtendedName(); var destinationTypeName = destinationType.ExtendedName(); if (matcherBehaviors.HasFlag(MappingMatcherBehaviors.IgnoreCase)) { sourceTypeName = sourceTypeName.ToLower(); destinationTypeName = destinationTypeName.ToLower(); } if (matcherBehaviors.HasFlag(MappingMatcherBehaviors.MatchIdenticalName) && sourceTypeName == destinationTypeName) { return true; } if (sourceTypeName.Length <= sourcePrefix.Length + sourceSuffix.Length) { return false; } if (destinationTypeName.Length <= destinationPrefix.Length + destinationSuffix.Length) { return false; } sourceTypeName = sourceTypeName.Substring(sourcePrefix.Length, sourceTypeName.Length - sourcePrefix.Length - sourceSuffix.Length); destinationTypeName = destinationTypeName.Substring(destinationPrefix.Length, destinationTypeName.Length - destinationPrefix.Length - destinationSuffix.Length); return sourceTypeName == destinationTypeName; }); }
public static MappingMatcher TypeNameMatcher(string sourceTypeNameMatcher, string destinationTypeNameMatcher, MappingMatcherBehaviors matcherBehaviors = MappingMatcherBehaviors.None) { if (string.IsNullOrEmpty(sourceTypeNameMatcher)) { throw new ArgumentException("Must not be null or empty", nameof(sourceTypeNameMatcher)); } if (string.IsNullOrEmpty(destinationTypeNameMatcher)) { throw new ArgumentException("Must not be null or empty", nameof(destinationTypeNameMatcher)); } var tokenizedStringMatcher = new TokenizedStringMatcher(sourceTypeNameMatcher, destinationTypeNameMatcher); return((Type sourceType, Type destinationType) => { if (sourceType == destinationType) { return matcherBehaviors.HasFlag(MappingMatcherBehaviors.MatchIdenticalType); } var sourceTypeName = sourceType.ExtendedName(); var destinationTypeName = destinationType.ExtendedName(); if (matcherBehaviors.HasFlag(MappingMatcherBehaviors.IgnoreCase)) { sourceTypeName = sourceTypeName.ToLower(); destinationTypeName = destinationTypeName.ToLower(); } if (matcherBehaviors.HasFlag(MappingMatcherBehaviors.MatchIdenticalName) && sourceTypeName == destinationTypeName) { return true; } return tokenizedStringMatcher.IsMatch(sourceTypeName, destinationTypeName); }); }