public PDFDataBindEventHandler GetDataBindingExpression(string expressionvalue, Type classType, System.Reflection.PropertyInfo forProperty) { PDFValueConverter valConv; if (ParserDefintionFactory.IsSimpleObjectType(forProperty.PropertyType, out valConv)) { BindingXPathExpression expr = BindingXPathExpression.Create(expressionvalue, valConv, forProperty); return(new PDFDataBindEventHandler(expr.BindComponent)); } else if (ParserDefintionFactory.IsCustomParsableObjectType(forProperty.PropertyType, out valConv)) { BindingXPathExpression expr = BindingXPathExpression.Create(expressionvalue, valConv, forProperty); return(new PDFDataBindEventHandler(expr.BindComponent)); } else if (forProperty.PropertyType == typeof(Object)) { valConv = null; var expr = BindingXPathExpression.Create(expressionvalue, valConv, forProperty); return(new PDFDataBindEventHandler(expr.BindComponent)); } else { throw new PDFParserException(string.Format(Errors.ParserAttributeMustBeSimpleOrCustomParsableType, forProperty.Name, forProperty.PropertyType)); } }
// // factory methods // #region public static BindingXPathExpression Create(string expr, PDFValueConverter convert, System.Reflection.PropertyInfo property) /// <summary> /// Returns a new concrete instance of a BindingXPathExpression that can be called from a components /// DataBinding event and set the value of the property. /// </summary> /// <param name="expr">The binding XPath expression to use</param> /// <param name="convert">A value converter to change the string result into the required type.</param> /// <param name="property">The property this expression is bound to.</param> /// <returns>The expression that ban be attached to an event</returns> public static BindingXPathExpression Create(string expr, PDFValueConverter convert, System.Reflection.PropertyInfo property) { if (null == property) { throw new ArgumentNullException("property"); } if (string.IsNullOrEmpty(expr)) { throw new ArgumentNullException("expr"); } //Run a quick compile to validat the return type System.Xml.XPath.XPathExpression compiled = System.Xml.XPath.XPathExpression.Compile(expr); BindingXPathExpression binding = null; switch (compiled.ReturnType) { case System.Xml.XPath.XPathResultType.Boolean: binding = new BindingXPathBoolExpression(); break; case System.Xml.XPath.XPathResultType.NodeSet: binding = new BindingXPathNodeSetExpression(); break; case System.Xml.XPath.XPathResultType.Number: case System.Xml.XPath.XPathResultType.String: binding = new BindingXPathValueExpression(); break; case System.Xml.XPath.XPathResultType.Error: throw new PDFParserException(String.Format(Errors.InvalidXPathExpression, expr)); case System.Xml.XPath.XPathResultType.Any: default: throw new PDFParserException(String.Format(Errors.ReturnTypeOfXPathExpressionCouldNotBeDetermined, expr)); } binding._converter = convert; binding._expr = expr; binding._compiled = compiled; binding._property = property; return(binding); }