//
        // Add - Adds/Updates the collection
        //
        protected override void Add(string prefix, string type)
        {
            IWebRequestCreate moduleToRegister = null;

            if (type == null)
            {
                return;
            }

            // converts a type an object of type

            try {
                moduleToRegister = (IWebRequestCreate)Activator.CreateInstance(
                    Type.GetType(type, true, true),
                    BindingFlags.CreateInstance
                    | BindingFlags.Instance
                    | BindingFlags.NonPublic
                    | BindingFlags.Public,
                    null,                                      // Binder
                    new object[0],                             // no arguments
                    CultureInfo.InvariantCulture
                    );
            }
            catch (Exception e)  {
                //
                // throw exception for config debugging
                //

                throw new ConfigurationException("WebRequestModuleHandler", e);
            }


            bool matched         = false;
            int  indexToInsertAt = FindPrefix(prefix, ref matched);

            // When we get here either i contains the index to insert at or
            // we've had an error if we've already found it matched

            if (!matched)
            {
                // no adding on duplicates
                _res.Insert(indexToInsertAt,
                            new WebRequestPrefixElement(prefix, moduleToRegister)
                            );
            }
            else
            {
                // update
                _res[indexToInsertAt] =
                    new WebRequestPrefixElement(prefix, moduleToRegister);
            }

            return;
        }
Ejemplo n.º 2
0
        //
        // Add - Adds/Updates the collection 
        //
        protected override void Add(string prefix, string type)
        {                   
            IWebRequestCreate moduleToRegister = null;

            if (type == null ) {
                return;
            }

            // converts a type an object of type

            try {
                moduleToRegister = (IWebRequestCreate)Activator.CreateInstance(
                                                Type.GetType(type, true, true),
                                                BindingFlags.CreateInstance
                                                | BindingFlags.Instance
                                                | BindingFlags.NonPublic
                                                | BindingFlags.Public,
                                                null,          // Binder
                                                new object[0], // no arguments
                                                CultureInfo.InvariantCulture
                                                );            
            }
            catch (Exception e)  {
                //
                // throw exception for config debugging
                //

                throw new ConfigurationException("WebRequestModuleHandler", e);                
            }

           
            bool matched = false; 
            int indexToInsertAt = FindPrefix(prefix, ref matched);

            // When we get here either i contains the index to insert at or
            // we've had an error if we've already found it matched

            if (!matched) {
                // no adding on duplicates
                _res.Insert(indexToInsertAt,
                            new WebRequestPrefixElement(prefix, moduleToRegister)
                           );
            } else {
                // update
                _res[indexToInsertAt] =                    
                            new WebRequestPrefixElement(prefix, moduleToRegister);
                
            }

            return;
        }