/// <summary>
        /// Returns true if the type specified is a custom parsable type - and should have a static (shared) Parse method on the definition on it.
        /// The convert parameter will be set to a delegate that calls this method.
        /// </summary>
        /// <param name="type">The type to check for parsability</param>
        /// <param name="convert">If it is a custom parsable type then it will be set to the converter of this type</param>
        /// <returns>True if the type is decoated with a custom parsable type</returns>
        public static bool IsCustomParsableObjectType(Type type, out PDFValueConverter convert)
        {
            PDFParsableValueAttribute valattr = GetCustomAttribute <PDFParsableValueAttribute>(type, true);

            if (null != valattr)
            {
                convert = ConvertObjects.GetParsableValueConverter(type);
                return(null != convert);
            }
            else
            {
                convert = null;
                return(false);
            }
        }
예제 #2
0
        //
        // 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);
        }
 /// <summary>
 /// Returns true if the type is a simple convertable value from a string.
 /// And sets the converter to the metho that will convert a string to this required type.
 /// If not its null and false.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="convert"></param>
 /// <returns></returns>
 public static bool IsSimpleObjectType(Type type, out PDFValueConverter convert)
 {
     return(ConvertObjects.IsSimpleObjectType(type, out convert));
 }
예제 #4
0
 /// <summary>
 /// Protecxted constructor that accepts the type and
 /// </summary>
 /// <param name="parsetype"></param>
 protected ParseableConverter(Type parsetype)
 {
     this.Type      = parsetype;
     XmlConverter   = new PDFXmlConverter(this.ConvertXml);
     ValueConverter = new PDFValueConverter(this.ConvertValue);
 }
        public static bool IsSimpleObjectType(Type type, out PDFValueConverter convert)
        {
            bool result = false;

            if (type.IsEnum)
            {
                convert = new PDFValueConverter(ConvertObjects.ToEnum);
                return(true);
            }
            TypeCode code = Type.GetTypeCode(type);

            switch (code)
            {
            case TypeCode.Boolean:
                convert = ConvertToBool;
                result  = true;
                break;

            case TypeCode.Byte:
                convert = ConvertToByte;
                result  = true;
                break;

            case TypeCode.Char:
                convert = ConvertToChar;
                result  = true;
                break;

            case TypeCode.DBNull:
                convert = ConvertToDBNull;
                result  = true;
                break;

            case TypeCode.DateTime:
                convert = ConvertToDateTime;
                result  = true;
                break;

            case TypeCode.Decimal:
                convert = ConvertToDecimal;
                result  = true;
                break;

            case TypeCode.Double:
                convert = ConvertToDouble;
                result  = true;
                break;

            case TypeCode.Int16:
                convert = ConvertToInt16;
                result  = true;
                break;

            case TypeCode.Int32:
                convert = ConvertToInt32;
                result  = true;
                break;

            case TypeCode.Int64:
                convert = ConvertToInt64;
                result  = true;
                break;

            case TypeCode.SByte:
                convert = ConvertToSByte;
                result  = true;
                break;

            case TypeCode.Single:
                convert = ConvertToFloat;
                result  = true;
                break;

            case TypeCode.String:
                convert = ConvertToString;
                result  = true;
                break;

            case TypeCode.UInt16:
                convert = ConvertToUInt16;
                result  = true;
                break;

            case TypeCode.UInt32:
                convert = ConvertToUInt32;
                result  = true;
                break;

            case TypeCode.UInt64:
                convert = ConvertToUInt64;
                result  = true;
                break;

            case TypeCode.Object:
                if (type == typeof(Guid))
                {
                    convert = ConvertToGuid;
                    result  = true;
                }
                else if (type == typeof(DateTime))
                {
                    convert = ConvertToDateTime;
                    result  = true;
                }
                else if (type == typeof(TimeSpan))
                {
                    convert = ConvertToTimeSpan;
                    result  = true;
                }
                else if (type == typeof(Uri))
                {
                    convert = ConvertToUri;
                    result  = true;
                }
                else
                {
                    convert = null;
                    result  = false;
                }
                break;

            case TypeCode.Empty:
            default:
                convert = null;
                result  = false;
                break;
            }
            return(result);
        }