Example #1
0
        string IDesignerSerializationManager.GetName(object value)
        {
            string str = null;

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            this.CheckSession();
            if (this.namesByInstance != null)
            {
                str = (string)this.namesByInstance[value];
            }
            if ((str != null) || !(value is IComponent))
            {
                return(str);
            }
            ISite site = ((IComponent)value).Site;

            if (site == null)
            {
                return(str);
            }
            INestedSite site2 = site as INestedSite;

            if (site2 != null)
            {
                return(site2.FullName);
            }
            return(site.Name);
        }
        private bool CanCacheComponent(IDesignerSerializationManager manager, object value, PropertyDescriptorCollection props)
        {
            IComponent component = value as IComponent;

            if (component != null)
            {
                if (component.Site != null)
                {
                    INestedSite site = component.Site as INestedSite;
                    if ((site != null) && !string.IsNullOrEmpty(site.FullName))
                    {
                        return(false);
                    }
                }
                if (props == null)
                {
                    props = TypeDescriptor.GetProperties(component);
                }
                foreach (PropertyDescriptor descriptor in props)
                {
                    if (typeof(IComponent).IsAssignableFrom(descriptor.PropertyType) && !descriptor.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden))
                    {
                        MemberCodeDomSerializer serializer = (MemberCodeDomSerializer)manager.GetSerializer(descriptor.GetType(), typeof(MemberCodeDomSerializer));
                        if ((serializer != null) && serializer.ShouldSerialize(manager, value, descriptor))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
            /// <summary>
            ///     Retrieves the component name from the site.
            /// </summary>
            internal string GetComponentName(object instance)
            {
                IComponent comp = instance as IComponent;

                if (comp != null)
                {
                    ISite site = comp.Site;
                    if (site != null)
                    {
#if FEATURE_NESTED_SITE
                        INestedSite nestedSite = site as INestedSite;
                        if (nestedSite != null)
                        {
                            return(nestedSite.FullName);
                        }
                        else
#endif
                        {
                            return(site.Name);
                        }
                    }
                }

                return(null);
            }
Example #4
0
            public SelectToolStripMenuItem(Component c, IServiceProvider provider)
            {
                this.comp            = c;
                this.serviceProvider = provider;
                string fullName = null;

                if (this.comp != null)
                {
                    ISite site = this.comp.Site;
                    if (site != null)
                    {
                        INestedSite site2 = site as INestedSite;
                        if ((site2 != null) && !string.IsNullOrEmpty(site2.FullName))
                        {
                            fullName = site2.FullName;
                        }
                        else if (!string.IsNullOrEmpty(site.Name))
                        {
                            fullName = site.Name;
                        }
                    }
                }
                this.Text      = System.Design.SR.GetString("ToolStripSelectMenuItem", new object[] { fullName });
                this._itemType = c.GetType();
            }
Example #5
0
            /// <summary>
            ///     Retrieves the component name from the site.
            /// </summary>
            internal string GetComponentName(object instance)
            {
                IComponent comp = instance as IComponent;
                ISite      site = comp?.Site;

                if (site != null)
                {
                    INestedSite nestedSite = site as INestedSite;
                    return((nestedSite?.FullName) ?? site.Name);
                }

                return(null);
            }
        public void CreateSite_NullOwnerSite_Success(string name)
        {
            var component = new Component();

            var         owner     = new Component();
            var         container = new SubNestedContainer(owner);
            INestedSite site      = Assert.IsAssignableFrom <INestedSite>(container.CreateSiteEntryPoint(component, name));

            Assert.Same(component, site.Component);
            Assert.Same(container, site.Container);
            Assert.False(site.DesignMode);
            Assert.Equal(name, site.Name);
            Assert.Equal(name, site.FullName);
        }
        public void CreateSite_SetSiteName_Success(string value)
        {
            var component = new Component();

            var owner     = new Component();
            var container = new SubNestedContainer(owner);

            container.Add(component, "name");

            INestedSite site = Assert.IsAssignableFrom <INestedSite>(component.Site);

            site.Name = value;
            Assert.Equal(value, site.Name);
        }
        public void CreateSite_GetSiteServiceType_ReturnsExpected()
        {
            var component = new Component();

            var owner     = new Component();
            var container = new SubNestedContainer(owner);

            container.Add(component);

            INestedSite site = Assert.IsAssignableFrom <INestedSite>(component.Site);

            Assert.Same(site, site.GetService(typeof(ISite)));
            Assert.Same(container, site.GetService(typeof(INestedContainer)));
            Assert.Same(container, site.GetService(typeof(IContainer)));
            Assert.Null(site.GetService(typeof(INestedSite)));
            Assert.Null(site.GetService(typeof(int)));
            Assert.Null(site.GetService(null));
        }
        public void Add_NonNullOwnerSite_Success(string name)
        {
            var component = new Component();

            var owner = new Component()
            {
                Site = new Site()
                {
                    DesignMode = true
                }
            };
            var container = new SubNestedContainer(owner);

            container.Add(component, name);

            INestedSite site = Assert.IsAssignableFrom <INestedSite>(component.Site);

            Assert.Same(component, site.Component);
            Assert.Same(container, site.Container);
            Assert.True(site.DesignMode);
            Assert.Equal(name, site.Name);
            Assert.Equal(name == null ? null : "SiteName." + name, site.FullName);
        }
Example #10
0
            /// <summary>
            ///     Retrieves the component name from the site.
            /// </summary>
            internal string GetComponentName(object instance)
            {
                IComponent comp = instance as IComponent;

                if (comp != null)
                {
                    ISite site = comp.Site;
                    if (site != null)
                    {
                        INestedSite nestedSite = site as INestedSite;
                        if (nestedSite != null)
                        {
                            return(nestedSite.FullName);
                        }
                        else
                        {
                            return(site.Name);
                        }
                    }
                }

                return(null);
            }