/*
         * This code is only used in the non-compiled mode.
         * It is used at design-time and when the user calls Page.ParseControl.
         */
        internal virtual object BuildObject()
        {
            Debug.Assert(InDesigner || NonCompiledPage, "Expected to be in designer mode.");

            // If it has a ConstructorNeedsTagAttribute, it needs a tag name
            ConstructorNeedsTagAttribute cnta = (ConstructorNeedsTagAttribute)
                                                TypeDescriptor.GetAttributes(ControlType)[typeof(ConstructorNeedsTagAttribute)];

            Object obj;

            if (cnta != null && cnta.NeedsTag)
            {
                // Create the object, using its ctor that takes the tag name
                Object[] args = new Object[] { TagName };
                obj = HttpRuntime.CreatePublicInstance(_ctrlType, args);
            }
            else
            {
                // Create the object
                obj = HttpRuntime.CreatePublicInstance(_ctrlType);
            }

            InitObject(obj);
            return(obj);
        }
		public void Deny_Unrestricted ()
		{
			ConstructorNeedsTagAttribute a1 = new ConstructorNeedsTagAttribute ();
			Assert.IsFalse (a1.NeedsTag, "NeedsTag-1");
			ConstructorNeedsTagAttribute a2 = new ConstructorNeedsTagAttribute (true);
			Assert.IsTrue (a2.NeedsTag, "NeedsTag-2");
		}
Esempio n. 3
0
        internal virtual object CreateInstance()
        {
            // HtmlGenericControl, HtmlTableCell...
            object [] atts = type.GetCustomAttributes(typeof(ConstructorNeedsTagAttribute), true);
            object [] args = null;
            if (atts != null && atts.Length > 0)
            {
                ConstructorNeedsTagAttribute att = (ConstructorNeedsTagAttribute)atts [0];
                if (att.NeedsTag)
                {
                    args = new object [] { tagName }
                }
                ;
            }

            return(Activator.CreateInstance(type, args));
        }