Ejemplo n.º 1
0
        private static object ParseAndBind(BaseHtmlAttribute attribute, Type objectType, CQ nodeForProperty)
        {
            // Parse
            var parsedValue = ParserFactory.Instance.GetParser(attribute.GetType()).Parse(nodeForProperty, attribute);

            // Bind
            var boundValue = BinderFactory.Instance.GetBinder(objectType).Handle(parsedValue, nodeForProperty, objectType, attribute);

            return(boundValue);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses some string value out of an <see cref="HtmlNode" /> selected by an <see cref="IFinder{T}" />
        /// </summary>
        /// <param name="node">The node that we are preparing to bind on.</param>
        /// <param name="attributeInstance">The instance of the attribute that is being used to perform binding.</param>
        /// <returns>The string value of the element to pass to the binder for binding to the POCO.</returns>
        /// <exception cref="ArgumentNullException">Thrown if either <paramref name="node"/> or <paramref name="attributeInstance"/> is null.</exception>
        public string Parse(CQ node, BaseHtmlAttribute attributeInstance)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            if (attributeInstance == null)
            {
                throw new ArgumentNullException(nameof(attributeInstance));
            }

            try
            {
                return(Parse(node, attributeInstance as HtmlElementAttribute));
            }
            catch (ArgumentNullException ex)
            {
                throw new NapParsingException($"Attribute {attributeInstance.GetType().FullName} is not of the correct type to be handled by ${GetType().FullName}.", ex);
            }
        }