Code:
                         / FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / WebControlToolBoxItem.cs / 1 / WebControlToolBoxItem.cs
                        
                        
                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
//  
//----------------------------------------------------------------------------- 
namespace System.Web.UI.Design { 
 
    using System;
    using System.Design; 
    using System.Reflection;
    using System.Runtime.Serialization;
    using System.ComponentModel;
    using System.ComponentModel.Design; 
    using System.Diagnostics;
    using System.Drawing; 
    using System.Drawing.Design; 
    using System.IO;
    using System.Web.UI; 
    ///  
    /// 
    ///   
    [
    System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode), 
    Serializable 
    ]
    public class WebControlToolboxItem : ToolboxItem { 
        private string toolData = null;
        private int persistChildren = -1;
 
        ///  
        public WebControlToolboxItem() { 
        } 
        ///   
        /// 
        /// Initializes a new instance of the   class. 
        ///  
        public WebControlToolboxItem(Type type) : base(type) { 
            BuildMetadataCache(type);
        } 
 
        protected WebControlToolboxItem(SerializationInfo info, StreamingContext context) {
            Deserialize(info, context); 
        }
        private void BuildMetadataCache(Type type) {
            toolData = ExtractToolboxData(type); 
            persistChildren = ExtractPersistChildrenAttribute(type);
        } 
 
        ///  
        ///  
        ///    
        ///       Creates objects from each Type contained in this  
        ///       , and adds
        ///       them to the specified designer.  
        ///  
        protected override IComponent[] CreateComponentsCore(IDesignerHost host) { 
            throw new Exception(SR.GetString(SR.Toolbox_OnWebformsPage)); 
        }
 
        ///  
        ///  
        protected override void Deserialize(SerializationInfo info, StreamingContext context) {
            base.Deserialize(info, context); 
            toolData = info.GetString("ToolData"); 
            persistChildren = info.GetInt32("PersistChildren"); 
        }
 
        /// 
        ///   Extracts the value of the PersistChildrenAttribute attribute associated with the tool
        ///  
        private static int ExtractPersistChildrenAttribute(Type type) { 
            Debug.Assert(type != null);
 
            if (type != null) { 
                object[] attrs = type.GetCustomAttributes(typeof(PersistChildrenAttribute), /*inherit*/ true);
                if ((attrs != null) && (attrs.Length == 1)) { 
                    Debug.Assert(attrs[0] is PersistChildrenAttribute);
                    PersistChildrenAttribute pca = (PersistChildrenAttribute)attrs[0];
                    return (pca.Persist ? 1 : 0); 
                }
            } 
            return (PersistChildrenAttribute.Default.Persist ? 1 : 0); 
        }
 
        /// 
        ///   Extracts the value of the ToolboxData attribute associated with the tool
        ///  
        private static string ExtractToolboxData(Type type) { 
            Debug.Assert(type != null);
 
            string toolData = String.Empty; 
            if (type != null) {
                object[] attrs = type.GetCustomAttributes(typeof(ToolboxDataAttribute), /*inherit*/ false); 
                if ((attrs != null) && (attrs.Length == 1)) {
                    Debug.Assert(attrs[0] is ToolboxDataAttribute);
                    ToolboxDataAttribute toolDataAttr = (ToolboxDataAttribute)attrs[0];
 
                    toolData = toolDataAttr.Data;
                } 
                else { 
                    string typeName = type.Name;
                    toolData = "<{0}:" + typeName + " runat=\"server\">{0}:" + typeName + ">"; 
                }
            }
            return toolData; 
        }
 
        ///   
        public object GetToolAttributeValue(IDesignerHost host, Type attributeType) {
            if (attributeType == typeof(PersistChildrenAttribute)) { 
                if (persistChildren == -1) {
                    Type toolType = GetToolType(host);
                    persistChildren = ExtractPersistChildrenAttribute(toolType);
                } 
                return ((persistChildren == 1) ? true : false); 
            } 
            throw new ArgumentException(SR.GetString(SR.Toolbox_BadAttributeType)); 
        }
        ///  
        ///  
        ///    Gets the toolbox HTML that represents the corresponding web control on the design surface. 
        ///   
        public string GetToolHtml(IDesignerHost host) { 
            if (toolData != null) {
                return toolData; 
            }
            // Create the HTML data that is to be droppped.
            Type toolType = GetToolType(host); 
            toolData = ExtractToolboxData(toolType);
 
            return toolData; 
        }
 
        ///  
        public Type GetToolType(IDesignerHost host) {
            if (host == null) {
                throw new ArgumentNullException("host"); 
            }
 
            return GetType(host, AssemblyName, TypeName, true); 
        }
 
        ///  
        public override void Initialize(Type type) {
            base.Initialize(type);
            BuildMetadataCache(type); 
        }
 
        ///   
        ///  
        protected override void Serialize(SerializationInfo info, StreamingContext context) { 
            base.Serialize(info, context);
            info.AddValue("ToolData", toolData);
            info.AddValue("PersistChildren", persistChildren); 
        }
    } 
} 
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        
                        
                        
                        
                    Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- _DigestClient.cs
 - XmlSerializer.cs
 - InputLanguageCollection.cs
 - RuntimeArgumentHandle.cs
 - OdbcTransaction.cs
 - PermissionToken.cs
 - ActiveXContainer.cs
 - StringUtil.cs
 - COM2Properties.cs
 - Point.cs
 - SID.cs
 - MergeLocalizationDirectives.cs
 - HistoryEventArgs.cs
 - DSASignatureDeformatter.cs
 - DataGridViewTextBoxColumn.cs
 - HideDisabledControlAdapter.cs
 - AlternateView.cs
 - WebPartZone.cs
 - Regex.cs
 - CriticalExceptions.cs
 - GridEntryCollection.cs
 - HttpResponseBase.cs
 - CompilerWrapper.cs
 - ActiveXHelper.cs
 - CodeMethodReturnStatement.cs
 - ElapsedEventArgs.cs
 - DataControlField.cs
 - StaticContext.cs
 - DodSequenceMerge.cs
 - WsatAdminException.cs
 - GridViewRowPresenterBase.cs
 - ListViewSelectEventArgs.cs
 - WizardSideBarListControlItemEventArgs.cs
 - MergePropertyDescriptor.cs
 - GraphicsPath.cs
 - TransformerInfo.cs
 - XmlDataDocument.cs
 - VolatileResourceManager.cs
 - TypeElementCollection.cs
 - CorruptingExceptionCommon.cs
 - ManagementObjectCollection.cs
 - PerformanceCounterPermissionAttribute.cs
 - WebConvert.cs
 - SqlFlattener.cs
 - sqlser.cs
 - MarshalDirectiveException.cs
 - EventMappingSettingsCollection.cs
 - DataBoundControlHelper.cs
 - HtmlButton.cs
 - XpsFilter.cs
 - DataFormats.cs
 - XmlC14NWriter.cs
 - IISMapPath.cs
 - PersonalizationAdministration.cs
 - AuthorizationRuleCollection.cs
 - PrintDialogDesigner.cs
 - ContextQuery.cs
 - MulticastDelegate.cs
 - ValidationPropertyAttribute.cs
 - HierarchicalDataSourceControl.cs
 - OperationAbortedException.cs
 - LoadWorkflowByKeyAsyncResult.cs
 - SimpleFieldTemplateFactory.cs
 - FixedPage.cs
 - SelectionRange.cs
 - RichTextBox.cs
 - LayoutEvent.cs
 - UIPermission.cs
 - EntityExpressionVisitor.cs
 - QilGenerator.cs
 - WebPartTracker.cs
 - WebBrowserNavigatingEventHandler.cs
 - PaginationProgressEventArgs.cs
 - JournalEntryListConverter.cs
 - Triplet.cs
 - Boolean.cs
 - StsCommunicationException.cs
 - ValueSerializerAttribute.cs
 - DataView.cs
 - DurableOperationContext.cs
 - DataControlFieldCollection.cs
 - SRGSCompiler.cs
 - MetadataUtil.cs
 - StandardCommands.cs
 - RemotingAttributes.cs
 - CompilationSection.cs
 - WeakEventTable.cs
 - Attributes.cs
 - SoapDocumentServiceAttribute.cs
 - NumberEdit.cs
 - GroupBox.cs
 - SizeAnimation.cs
 - CrossContextChannel.cs
 - precedingquery.cs
 - PassportAuthenticationEventArgs.cs
 - XmlUtil.cs
 - PerformanceCounterCategory.cs
 - QilDataSource.cs
 - DocumentViewerConstants.cs
 - MetadataPropertyCollection.cs