Ejemplo n.º 1
0
        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));
            }
        }
        public void IsCustomParsableObjectTypeTest()
        {
            IFormatProvider   invariant = System.Globalization.CultureInfo.InvariantCulture;
            PDFValueConverter convert;
            Type   type       = typeof(Scryber.Drawing.PDFThickness); //thickness is parsable
            string thickvalue = "12 45.3in 12.5 4mm";

            bool expected = true;
            bool actual   = ParserDefintionFactory.IsCustomParsableObjectType(type, out convert);

            Assert.AreEqual(expected, actual, "PDFThickness is not registered as parsable");
            Assert.IsNotNull(convert);
            Scryber.Drawing.PDFThickness thick = (Scryber.Drawing.PDFThickness)convert(thickvalue, type, invariant);
            Assert.AreEqual(thick.Top, (Scryber.Drawing.PDFUnit) 12);
            Assert.AreEqual(thick.Right, new Scryber.Drawing.PDFUnit(45.3, Scryber.Drawing.PageUnits.Inches));
            Assert.AreEqual(thick.Bottom, (Scryber.Drawing.PDFUnit) 12.5);
            Assert.AreEqual(thick.Left, new Scryber.Drawing.PDFUnit(4, Scryber.Drawing.PageUnits.Millimeters));

            type     = typeof(Scryber.Drawing.PDFPen); //pen is not parsable
            expected = false;
            actual   = ParserDefintionFactory.IsCustomParsableObjectType(type, out convert);
            Assert.AreEqual(expected, actual);
            Assert.IsNull(convert);
        }