private IEnumerable <ITypeMappingItem> ToTypeMappingItems(string trimmedContextWithoutHeader) { var stringBuilder = new StringBuilder(); TypeMappingItem currentTypeMappingItem = null; var isInSourceContext = false; var isInDestinationContext = false; foreach (var currentChar in trimmedContextWithoutHeader) { stringBuilder.Append(currentChar); var currentString = stringBuilder.ToString(); if (currentString.EndsWith(sourceTypeStartContext) && currentTypeMappingItem == null && !isInSourceContext) { currentTypeMappingItem = new TypeMappingItem(); isInSourceContext = true; stringBuilder.Clear(); } if (currentString.EndsWith(sourceTypeEndContext) && currentTypeMappingItem != null && isInSourceContext) { currentTypeMappingItem.SourceType = currentString.Substring(0, currentString.Length - sourceTypeEndContext.Length); isInSourceContext = false; stringBuilder.Clear(); } if (currentString.EndsWith(sourceDestinationSeparator) && currentTypeMappingItem != null && !isInSourceContext && !isInDestinationContext) { if (!String.IsNullOrWhiteSpace(currentString.Substring(0, currentString.Length - sourceDestinationSeparator.Length))) { throw new Exception("Formatting errors"); } stringBuilder.Clear(); } if (currentString.EndsWith(destinationTypeStartContext) && currentTypeMappingItem != null && !isInSourceContext && !isInDestinationContext) { if (!String.IsNullOrWhiteSpace(currentString.Substring(0, currentString.Length - destinationTypeStartContext.Length))) { throw new Exception("Formatting errors"); } isInDestinationContext = true; stringBuilder.Clear(); } if (currentString.EndsWith(destinationTypeEndContext) && currentTypeMappingItem != null && !isInSourceContext && isInDestinationContext) { currentTypeMappingItem.DestinationType = currentString.Substring(0, currentString.Length - destinationTypeEndContext.Length); isInDestinationContext = false; yield return(currentTypeMappingItem); currentTypeMappingItem = null; stringBuilder.Clear(); } } }
private TypeMappingItem ToTypeMappingItem(string itemAsString) { var splitted = Regex.Split(itemAsString, "\\)<-\\]\\s*=>\\s*\\[->\\(").ToList(); var sourceType = splitted[0].TrimStart().Substring("[->(".Length); var destinationType = splitted[1].TrimEnd(); if (destinationType.EndsWith(",")) { destinationType = destinationType.Substring(0, destinationType.Length - 1); } destinationType = destinationType.TrimEnd().Substring(0, destinationType.Length - ")<-]".Length); var result = new TypeMappingItem() { SourceType = sourceType, DestinationType = destinationType }; return(result); }