public static string GetParameters(this ExtensionDefinition extension, SourceDefinition sourceDefinition, string valueGenericName)
 => String
 .Join
 (
     String.Empty,
     extension
     .Parameters
     .Where(p => !p.Value.HasValue())
     .Select(p => $", {p.GetTypeName(GetValidatorValueType(sourceDefinition, valueGenericName, Option.Some(extension.Validator)))} {p.Name}{p.DefaultValue.Match(v => $" = {v}", () => String.Empty)}")
 );
        public bool TryGetOrAddChild(ExtensionDefinition extension, out ExtensionPathNode node)
        {
            if (!DataType.Match(value => extension.DataType.Match(newValue => newValue == value, () => true), () => true))
            {
                node = null;
                return(false);
            }

            _extensions.Add(extension);

            if (!_children.TryGetValue(extension.Validator, out var child))
            {
                child = new ExtensionPathNode(extension.Validator, this);

                _children.Add(extension.Validator, child);
            }

            node = child;
            return(true);
        }
 public static string GetArguments(this ExtensionDefinition extension)
 => String.Join(", ", extension.Parameters.Select(p => p.Value.Match(v => v, () => p.Name)));
        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));
        }
 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>()));
        public static IEnumerable <string> GenerateExtensionOne(SourceDefinition sourceDefinition, Option <string> dataType, ExtensionDefinition extension)
        {
            if (sourceDefinition.ValueType == ValueType.Value && extension.Validator.ValueType != ValueType.Value)
            {
                throw new Exception("Array extensions cannot be generated for value type sources.");
            }

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

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

            yield return(PopulateTemplate(_validatorExtensionTemplate, sourceDefinition, valueGenericName, genericParameters, null, null, extension, false, false, true));

            yield return(PopulateTemplate(_singleExtensionTemplate, sourceDefinition, valueGenericName, genericParameters, null, null, extension, false, 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)}");