예제 #1
0
 public ExtensionPathNode(ValidatorDefinition validator, ExtensionPathNode parent)
 {
     Validator = validator;
     Parent    = parent;
 }
예제 #2
0
 public static string GetName(this ValidatorDefinition validator, SourceDefinition sourceDefinition, string valueGenericName)
 => validator.GetValidatorName(sourceDefinition.GetValidatorValueType(valueGenericName, Option.Some(validator)));
예제 #3
0
        public static IEnumerable <string> GenerateExtensionThree(SourceDefinition sourceDefinition, Option <string> dataType, ValidatorDefinition validatorOne, ValidatorDefinition validatorTwo, ExtensionDefinition extension)
        {
            if (sourceDefinition.ValueType == ValueType.Value && (validatorOne.ValueType != ValueType.Value || validatorTwo.ValueType != ValueType.Value || extension.Validator.ValueType != ValueType.Value))
            {
                throw new Exception("Array extensions cannot be generated for value type sources.");
            }

            var valueGenericName = dataType.Match(_ => _, () => "TValue");

            var genericParameters = dataType.Match(_ => Array.Empty <string>(), () => new[] { "TValue" });

            yield return(PopulateTemplate(_tripleExtensionTemplate, sourceDefinition, valueGenericName, genericParameters, validatorOne, validatorTwo, extension, false, false));

            yield return(PopulateTemplate(_tripleExtensionTemplate, sourceDefinition, valueGenericName, genericParameters, validatorOne, validatorTwo, extension, true, false));

            yield return(PopulateTemplate(_tripleExtensionTemplate, sourceDefinition, valueGenericName, genericParameters, validatorOne, validatorTwo, extension, false, true));

            yield return(PopulateTemplate(_tripleExtensionTemplate, sourceDefinition, valueGenericName, genericParameters, validatorOne, validatorTwo, extension, true, true));
        }
예제 #4
0
 private static string GetValueForValidator(SourceDefinition sourceDefinition, ValidatorDefinition validator, string valueGenericName)
 => sourceDefinition.ValueType == ValueType.Array && validator?.ValueType == ValueType.Value ? $"{valueGenericName}[]" : valueGenericName;
예제 #5
0
 private static string PopulateTemplate(string template, SourceDefinition sourceDefinition, string valueGenericName, string[] genericParameters, ValidatorDefinition validatorOne, ValidatorDefinition validatorTwo, ExtensionDefinition extension, bool invertOne, bool invertTwo)
 => template
 .Replace("__Nullable__", $"{(sourceDefinition.IsNullable ? "Nullable" : String.Empty)}")
 .Replace("__InvertOne__", $"{(invertOne ? "Inverted" : "Standard")}")
 .Replace("__InvertTwo__", $"{(invertTwo ? "Inverted" : "Standard")}")
 .Replace("__StateValidator__", sourceDefinition.GetSourceName(Option.Some(valueGenericName)))
 .Replace("__ValueValidatorOne__", validatorOne?.GetValidatorName(GetValueForValidator(sourceDefinition, validatorOne, valueGenericName)) ?? String.Empty)
 .Replace("__ValueValidatorTwo__", validatorTwo?.GetValidatorName(GetValueForValidator(sourceDefinition, validatorTwo, valueGenericName)) ?? String.Empty)
 .Replace("__NewValueValidator__", extension?.Validator.GetValidatorName(GetValueForValidator(sourceDefinition, extension?.Validator, valueGenericName)) ?? String.Empty)
 .Replace("__TValueType__", sourceDefinition.ValueType == ValueType.Array ? $"{valueGenericName}[]" : valueGenericName)
 .Replace("__ExtensionName__", extension?.ExtensionName ?? String.Empty)
 .Replace("__GenericParameters__", genericParameters.Any() ? $"<{String.Join(", ", genericParameters)}>" : String.Empty)
 .Replace("__ExtensionParameters__", String.Join(String.Empty, extension?.Parameters.Where(p => !p.Value.HasValue()).Select(p => $", {p.GetTypeName(GetValueForValidator(sourceDefinition, extension?.Validator, valueGenericName))} {p.Name}{p.DefaultValue.Match(v => $" = {v}", () => String.Empty)}") ?? Enumerable.Empty <string>()))
 .Replace("__Parameters__", String.Join(", ", extension?.Parameters.Select(p => p.Value.Match(v => v, () => p.Name)) ?? Enumerable.Empty <string>()));
예제 #6
0
        public static IEnumerable <string> GenerateInvertExtensionTwo(SourceDefinition sourceDefinition, Option <string> dataType, ValidatorDefinition validatorOne)
        {
            if (sourceDefinition.ValueType == ValueType.Value && validatorOne.ValueType != ValueType.Value)
            {
                throw new Exception("Array extensions cannot be generated for value type sources.");
            }

            var valueGenericName = dataType.Match(_ => _, () => "TValue");

            var genericParameters = dataType.Match(_ => new[] { "TValueValidator" }, () => new[] { "TValueValidator", "TValue" });

            yield return(PopulateTemplate(_doubleNotTemplate, sourceDefinition, valueGenericName, genericParameters, validatorOne, null, null, false, false));

            yield return(PopulateTemplate(_doubleNotTemplate, sourceDefinition, valueGenericName, genericParameters, validatorOne, null, null, true, false));
        }
 private static string PopulateTemplate(string template, SourceDefinition sourceDefinition, string valueGenericName, string[] genericParameters, ValidatorDefinition validatorOne, ValidatorDefinition validatorTwo, ExtensionDefinition extension, bool invertOne, bool invertTwo, bool joinSourceAndValue = false)
 => template
 .Replace("__InvertOne__", $"{(invertOne ? "Inverted" : "Standard")}")
 .Replace("__InvertTwo__", $"{(invertTwo ? "Inverted" : "Standard")}")
 .Replace("__Inverted__", $"{((extension?.Invert ?? false) ? "Inverted" : "Standard")}")
 .Replace("__DataContainerFactory__", sourceDefinition.GetDataContainerFactoryType())
 .Replace("__StateValidator__", sourceDefinition.GetSourceName(valueGenericName))
 .Replace("__TSourceType__", joinSourceAndValue ? valueGenericName : SourceGeneric)
 .Replace("__TValueType__", valueGenericName)
 .Replace("__TDataValueType__", sourceDefinition.GetDataValueType(valueGenericName))
 .Replace("__TValidatorValueType__", sourceDefinition.GetValidatorValueType(valueGenericName, Option.None <ValidatorDefinition>()))
 .Replace("__ValueValidatorOne__", validatorOne?.GetName(sourceDefinition, valueGenericName) ?? String.Empty)
 .Replace("__ValueValidatorTwo__", validatorTwo?.GetName(sourceDefinition, valueGenericName) ?? String.Empty)
 .Replace("__NewValueValidator__", extension?.Validator.GetName(sourceDefinition, valueGenericName) ?? String.Empty)
 .Replace("__ExtensionName__", extension?.ExtensionName ?? String.Empty)
 .Replace("__GenericParameters__", HelperExtensions.ConstructorGenericParameters(genericParameters, Option.Create(!joinSourceAndValue, SourceGeneric)))
 .Replace("__ExtensionParameters__", extension?.GetParameters(sourceDefinition, valueGenericName) ?? String.Empty)
 .Replace("__Arguments__", extension?.GetArguments() ?? String.Empty)
 .Replace("__NotOpen__", $"{((extension?.Invert ?? false) ? @".Not(s => s" : String.Empty)}")
 .Replace("__NotClose__", $"{((extension?.Invert ?? false) ? ")" : String.Empty)}");