/// <summary> /// Begins mapping objects from Dapper. /// </summary> /// <typeparam name="TEntityType">The entity type to be mapped.</typeparam> /// <returns>The mapped entity.</returns> public TEntityType Start <TEntityType>() where TEntityType : class { lock (LockObject) { ItemEnumerator = Items.GetEnumerator(); SplitOnEnumerator = SplitOn.GetEnumerator(); CurrentSelectionSet = SelectionSet.GetSelectedFields(); MappedCount = 0; if (ItemEnumerator.MoveNext() && SplitOnEnumerator.MoveNext()) { var entity = ItemEnumerator.Current as TEntityType; MappedCount++; return(entity); } return(default(TEntityType)); } }
public string PerformOperation(string StringToManipulate) { string result = StringToManipulate; switch (_OperationType) { case OperationTypes.Split: char splitOn = SplitOn.ToCharArray()[0]; string[] tempSplit = result.Split(splitOn); int indexOfSplit = Index; if (tempSplit.Length > indexOfSplit) { result = tempSplit[indexOfSplit]; } else { result = ""; } break; case OperationTypes.Replace: string toReplace = Replace; string replaceWith = ReplaceWith; result = result.Replace(toReplace, replaceWith); break; case OperationTypes.EndWith: string endValue = Value; if (!result.TrimEnd().EndsWith(".")) { result += endValue; } break; } return(result); }
/// <summary> /// Maps the next object from Dapper. /// </summary> /// <typeparam name="TItemType">The item type to be mapped.</typeparam> /// <param name="context">The context used to map object from Dapper.</param> /// <param name="fieldNames">The names of one or more GraphQL fields associated with the item.</param> /// <param name="entityMapper">An optional entity mapper. This is used to map complex objects from Dapper mapping results.</param> /// <returns>The mapped item.</returns> public TItemType Next <TItemType>( IEnumerable <string> fieldNames, Func <IDictionary <string, Field>, IHaveSelectionSet, IHaveSelectionSet> getSelectionSet, IEntityMapper <TItemType> entityMapper = null) where TItemType : class { if (fieldNames == null) { throw new ArgumentNullException(nameof(fieldNames)); } if (ItemEnumerator == null || SplitOnEnumerator == null) { throw new NotSupportedException("Cannot call Next() before calling Start()"); } lock (LockObject) { var keys = fieldNames.Intersect(CurrentSelectionSet.Keys); if (keys.Any()) { TItemType item = default(TItemType); while ( ItemEnumerator.MoveNext() && SplitOnEnumerator.MoveNext()) { // Whether a non-null object exists at this position or not, // the SplitOn is expecting this type here, so we will yield it. if (SplitOnEnumerator.Current == typeof(TItemType)) { item = ItemEnumerator.Current as TItemType; break; } } if (entityMapper != null) { // Determine where the next entity mapper will get its selection set from IHaveSelectionSet selectionSet = getSelectionSet(CurrentSelectionSet, SelectionSet); var nextContext = new EntityMapContext { Items = Items.Skip(MappedCount), SelectionSet = selectionSet, SplitOn = SplitOn.Skip(MappedCount), }; using (nextContext) { item = entityMapper.Map(nextContext); // Update enumerators to skip past items already mapped var mappedCount = nextContext.MappedCount; MappedCount += nextContext.MappedCount; int i = 0; while ( // Less 1, the next time we iterate we // will advance by 1 as part of the iteration. i < mappedCount - 1 && ItemEnumerator.MoveNext() && SplitOnEnumerator.MoveNext()) { i++; } } } else { MappedCount++; } return(item); } } return(default(TItemType)); }