Ejemplo n.º 1
0
        /// <summary>
        /// Converts the current reader value to a runtime type and returns it
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="requiredType"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        internal static object ToType(XmlReader reader, Type requiredType, PDFGeneratorSettings settings)
        {
            string value = GetReaderValue(reader);
            string prefix;
            string name;
            int    sep = value.IndexOf(':');

            if (sep > 0)
            {
                name   = value.Substring(sep + 1);
                prefix = value.Substring(0, sep);
            }
            else
            {
                prefix = "";
                name   = value;
            }

            string ns = reader.LookupNamespace(prefix);
            bool   isremote;
            ParserClassDefinition cdefn;

            try
            {
                cdefn = ParserDefintionFactory.GetClassDefinition(name, ns, settings.ConformanceMode == ParserConformanceMode.Strict, out isremote);
            }
            catch (Exception ex)
            {
                throw new PDFParserException(string.Format(Errors.RuntimeTypeCouldNotBeDeterminedForReference, value), ex);
            }

            if (isremote)
            {
                if (settings.ConformanceMode == ParserConformanceMode.Strict)
                {
                    throw new ArgumentOutOfRangeException("isremote", String.Format(Errors.CannotUseRemoteTypeReferencesInATypeAttribute, reader.Value));
                }
                else
                {
                    settings.TraceLog.Add(TraceLevel.Error, "XML Parser", String.Format(Errors.CannotUseRemoteTypeReferencesInATypeAttribute, reader.Value));
                    return(null);
                }
            }

            if (null == cdefn)
            {
                settings.TraceLog.Add(TraceLevel.Error, "XML Parser", String.Format(Errors.RuntimeTypeCouldNotBeDeterminedForReference, reader.Value));
                return(typeof(NeverBeActivated));
            }
            else
            {
                return(cdefn.ClassType);
            }
        }
        internal static bool IsCustomParsableObjectType(Type type, out PDFValueConverter convert)
        {
            PDFParsableValueAttribute valattr = ParserDefintionFactory.GetCustomAttribute <PDFParsableValueAttribute>(type, true);

            if (null != valattr)
            {
                convert = ConvertObjects.GetParsableValueConverter(type);
                return(null != convert);
            }
            else
            {
                convert = null;
                return(false);
            }
        }