public SeederConfiguration Build()
        {
            var entitySettings = _entitySettingBuilders.Values
                                 .Select(b => b.Build(
                                             _defaultRepository,
                                             _defaultIdGeneration,
                                             _defaultPrimaryKeyNames))
                                 .ToList();

            if (!string.IsNullOrEmpty(_emptyStringMarker))
            {
                if (!(_typeTransformations[typeof(string)] is StringTransformation))
                {
                    throw new ConfigurationException("EmptyString marker can not be set, because the string transformation logic is overriden from you.", null);
                }

                _typeTransformations[typeof(string)] = new StringTransformation(_emptyStringMarker);
            }

            var configuration = new SeederConfiguration
            {
                AfterSaveAction             = _afterSaveAction,
                BeforeSaveAction            = _beforeSaveAction,
                DataProvider                = _dataProvider,
                DefaultIdGeneration         = _defaultIdGeneration,
                DefaultPrimaryKeyNames      = _defaultPrimaryKeyNames,
                DefaultRepository           = _defaultRepository,
                EntitySettings              = entitySettings,
                IsClearBeforeSeedingEnabled = _isClearBeforeSeedingEnabled,
                TypeTransformations         = _typeTransformations
            };

            var configurationValidator = new SeederConfigurationValidator();

            configurationValidator.IsValid(configuration);

            return(configuration);
        }
示例#2
0
        public static unsafe string Transform(this string value, StringTransformation transformation)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (value.Length == 0)
            {
                return(string.Empty);
            }

            var source = value.AsSpan();

            var length = source.Length;

            char *buffer = stackalloc char[length];

            var destination = new Span <char>(buffer, length);

            var count = source.Transform(destination, transformation);

            return(count == 0 ? string.Empty : new string(buffer, 0, count));
        }
        public static (StringTransformation.TransformationMethod, bool, int, string, string) DoReplacements(string original, StringTransformation transformation)
        {
            var updatedDescription = new string(original.ToCharArray());
            int amount             = 0;

            switch (transformation.Method)
            {
            case StringTransformation.TransformationMethod.Replace:
                var replaceResult = updatedDescription.Replace(transformation.PrimaryValue, transformation.SecondaryValue, transformation.IgnoreCase);
                amount             = replaceResult.Item1;
                updatedDescription = replaceResult.Item2;
                break;

            case StringTransformation.TransformationMethod.Remove:
                var removeResult = updatedDescription.Remove(transformation.PrimaryValue, transformation.IgnoreCase);
                amount             = removeResult.Item1;
                updatedDescription = removeResult.Item2;
                break;

            case StringTransformation.TransformationMethod.Append:
                updatedDescription = updatedDescription.Append(transformation.PrimaryValue);
                break;

            case StringTransformation.TransformationMethod.Prepend:
                updatedDescription = updatedDescription.Prepend(transformation.PrimaryValue);
                break;
            }


            return(transformation.Method, !updatedDescription.Equals(original), amount, updatedDescription, original);
        }
示例#4
0
        public static int Transform(this ReadOnlySpan <char> source, Span <char> destination, StringTransformation transformation)
        {
            if (source.IsEmpty)
            {
                return(0);
            }

            if (destination.Length < source.Length)
            {
                return(-1);
            }

            return(transformation(source, destination));
        }