Inheritance: RtfDestination
Exemplo n.º 1
0
        public static bool AddDestination(String destination, Object[] args)
        {
            if (destinations.ContainsKey(destination))
            {
                return(true);
            }

            String thisClass = "iTextSharp.text.rtf.parser.destinations." + (String)args[0];

            if (thisClass.IndexOf("RtfDestinationNull") >= 0)
            {
                destinations[destination] = RtfDestinationNull.GetInstance();
                return(true);
            }

            Type value = null;

            try {
                value = Type.GetType(thisClass);
            } catch {
                return(false);
            }
            if (value == null)
            {
                return(false);
            }

            RtfDestination c = null;

            if (destinationObjects.ContainsKey(value.Name))
            {
                c = (RtfDestination)destinationObjects[value.Name];
            }
            else
            {
                try {
                    c = (RtfDestination)value.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new Type[0], null).Invoke(null);
                } catch  {
                    return(false);
                }
            }

            c.SetParser(rtfParser);

            if (value.Equals(typeof(RtfDestinationInfo)))
            {
                ((RtfDestinationInfo)c).SetElementName(destination);
            }

            if (value.Equals(typeof(RtfDestinationStylesheetTable)))
            {
                ((RtfDestinationStylesheetTable)c).SetElementName(destination);
                ((RtfDestinationStylesheetTable)c).SetType((String)args[1]);
            }

            destinations[destination]      = c;
            destinationObjects[value.Name] = c;
            return(true);
        }
        public static bool AddDestination(string destination, object[] args)
        {
            if (_destinations.ContainsKey(destination))
            {
                return(true);
            }

            string thisClass = $"iTextSharp.text.rtf.parser.destinations.{(string) args[0]}";

            if (thisClass.IndexOf("RtfDestinationNull", StringComparison.Ordinal) >= 0)
            {
                _destinations[destination] = RtfDestinationNull.GetInstance();
                return(true);
            }

            Type value = null;

            try
            {
                value = Type.GetType(thisClass);
            }
            catch
            {
                return(false);
            }
            if (value == null)
            {
                return(false);
            }

            RtfDestination c = null;

            if (_destinationObjects.ContainsKey(value.Name))
            {
                c = (RtfDestination)_destinationObjects[value.Name];
            }
            else
            {
                try
                {
                    c = (RtfDestination)Activator.CreateInstance(value);
                }
                catch
                {
                    return(false);
                }
            }

            c.SetParser(_rtfParser);

            if (value == typeof(RtfDestinationInfo))
            {
                ((RtfDestinationInfo)c).SetElementName(destination);
            }

            if (value == typeof(RtfDestinationStylesheetTable))
            {
                ((RtfDestinationStylesheetTable)c).SetElementName(destination);
                ((RtfDestinationStylesheetTable)c).SetType((string)args[1]);
            }

            _destinations[destination]      = c;
            _destinationObjects[value.Name] = c;
            return(true);
        }