コード例 #1
0
        /// <summary>
        /// Reflects all types in the AssembyDefn's addembly and extracts all the types in theasembly in the required
        /// namespace that have the PDFParsableComponent attibute defined on the class - adding them to the NamespaceDefn
        /// </summary>
        /// <param name="ns"></param>
        /// <param name="assmdefn"></param>
        /// <param name="nsdefn"></param>
        private static void PopulateNamespaceFromAssembly(string ns, AssemblyDefn assmdefn, NamespaceDefn nsdefn)
        {
            if (assmdefn == null)
            {
                throw new ArgumentNullException("assmdefn");
            }
            if (assmdefn.InnerAssembly == null)
            {
                throw new ArgumentNullException("assmdefn.InnerAssembly");
            }

            if (null == nsdefn)
            {
                throw new ArgumentNullException("nsdefn");
            }

            Type[] all = assmdefn.InnerAssembly.GetTypes();
            foreach (Type t in all)
            {
                if (string.Equals(t.Namespace, ns))
                {
                    object[] attrs = t.GetCustomAttributes(typeof(PDFParsableComponentAttribute), false);
                    if (null != attrs && attrs.Length > 0)
                    {
                        PDFParsableComponentAttribute compattr = (PDFParsableComponentAttribute)attrs[0];
                        string name = compattr.ElementName;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = t.Name;
                        }

                        nsdefn.Add(name, t);

                        //check to see if it has a remote name too
                        attrs = t.GetCustomAttributes(typeof(PDFRemoteParsableComponentAttribute), false);
                        if (null != attrs && attrs.Length > 0)
                        {
                            PDFRemoteParsableComponentAttribute remattr = (PDFRemoteParsableComponentAttribute)attrs[0];
                            string remotename = remattr.ElementName;
                            if (string.IsNullOrEmpty(name))
                            {
                                remotename = t.Name + "-Ref";
                            }
                            nsdefn.RemoteTypes.Add(remotename, name);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Loads the class attributes for the type
        /// </summary>
        /// <param name="parsertype"></param>
        /// <param name="defn"></param>
        private static void LoadClassAttributes(Type parsertype, ParserClassDefinition defn)
        {
            PDFRequiredFrameworkAttribute req = GetCustomAttribute <PDFRequiredFrameworkAttribute>(parsertype, true);

            if (null != req)
            {
                if (req.Minimum != PDFRequiredFrameworkAttribute.Empty)
                {
                    if (defn.MinRequiredFramework == PDFRequiredFrameworkAttribute.Empty)
                    {
                        defn.MinRequiredFramework = req.Minimum;
                    }
                    else if (req.Minimum > defn.MinRequiredFramework)
                    {
                        defn.MinRequiredFramework = req.Minimum;
                    }
                }
                if (req.Maximum != PDFRequiredFrameworkAttribute.Empty)
                {
                    if (defn.MaxSupportedFramework == PDFRequiredFrameworkAttribute.Empty)
                    {
                        defn.MaxSupportedFramework = req.Maximum;
                    }
                    else if (req.Maximum < defn.MaxSupportedFramework)
                    {
                        defn.MaxSupportedFramework = req.Maximum;
                    }
                }
            }

            PDFRemoteParsableComponentAttribute remote = GetCustomAttribute <PDFRemoteParsableComponentAttribute>(parsertype, true);

            if (null != remote)
            {
                defn.SetRemoteParsable(true, remote.ElementName, remote.SourceAttribute);
            }
        }