コード例 #1
0
        private static TElement CreateElement(ArgKeyValuePairs pairs, PropertyOptionPairs properties)
        {
            var element = new TElement();

            foreach (var pair in pairs)
            {
                if (!properties.TryFindByOption(pair.Key, out var property))
                {
                    throw new UnboundTokenException(pair.Key);
                }

                var parsedValue = pair.Value.Parse(property.PropertyType);
                property.SetValue(element, parsedValue);
            }

            return(element);
        }
コード例 #2
0
        public void MethodTryFindByOptionShouldReturnFalseAndOutputNullWhenKeyIsNotFound(string[] options, string searchTerm)
        {
            var propertyName = nameof(PropertyOptionPair.Option);
            var property     = typeof(PropertyOptionPair).GetProperty(propertyName);
            var collection   = new List <PropertyOptionPair>();

            foreach (var option in options)
            {
                collection.Add(new PropertyOptionPair(property, option));
            }

            var pairs = new PropertyOptionPairs(collection);

            pairs.Count.Should().Be(collection.Count);

            var found = pairs.TryFindByOption(searchTerm, out var output);

            found.Should().BeFalse();
            output.Should().BeNull();
        }