Esempio n. 1
0
        private static Collector ReadFileCollector(YamlMappingNode collectorSequence)
        {
            var collector = new FileCollector();

            foreach (var pair in collectorSequence)
            {
                switch (pair.Key)
                {
                case YamlScalarNode s when s.Value == "role":
                    if (pair.Value is YamlScalarNode role)
                    {
                        collector.Role = role.Value;
                    }
                    else
                    {
                        throw new FormatException("Invalid non-scalar value in 'role'.");
                    }

                    break;

                case YamlScalarNode s when s.Value == "source":
                    if (pair.Value is YamlScalarNode source)
                    {
                        collector.Source = source.Value;
                    }
                    else
                    {
                        throw new FormatException("Invalid non-scalar value in 'source'.");
                    }

                    break;

                case YamlScalarNode s when s.Value == "destination":
                    if (pair.Value is YamlScalarNode dest)
                    {
                        collector.Destination = dest.Value;
                    }
                    else
                    {
                        throw new FormatException("Invalid non-scalar value in 'destination'.");
                    }

                    break;
                }
            }

            return(collector);
        }