Example #1
0
        private void SerializeControlHierarchy(IDesignerSerializationManager manager, IDesignerHost host, object value)
        {
            Control control = value as Control;

            if (control != null)
            {
                string str;
                IMultitargetHelperService service = host.GetService(typeof(IMultitargetHelperService)) as IMultitargetHelperService;
                if (control == host.RootComponent)
                {
                    str = "$this";
                    foreach (IComponent component in host.Container.Components)
                    {
                        if (!(component is Control) && !TypeDescriptor.GetAttributes(component).Contains(InheritanceAttribute.InheritedReadOnly))
                        {
                            string name = manager.GetName(component);
                            string str3 = (service == null) ? component.GetType().AssemblyQualifiedName : service.GetAssemblyQualifiedName(component.GetType());
                            if (name != null)
                            {
                                base.SerializeResourceInvariant(manager, ">>" + name + ".Name", name);
                                base.SerializeResourceInvariant(manager, ">>" + name + ".Type", str3);
                            }
                        }
                    }
                }
                else
                {
                    str = manager.GetName(value);
                    if (str == null)
                    {
                        return;
                    }
                }
                base.SerializeResourceInvariant(manager, ">>" + str + ".Name", manager.GetName(value));
                base.SerializeResourceInvariant(manager, ">>" + str + ".Type", (service == null) ? control.GetType().AssemblyQualifiedName : service.GetAssemblyQualifiedName(control.GetType()));
                Control parent = control.Parent;
                if ((parent != null) && (parent.Site != null))
                {
                    string str4;
                    if (parent == host.RootComponent)
                    {
                        str4 = "$this";
                    }
                    else
                    {
                        str4 = manager.GetName(parent);
                    }
                    if (str4 != null)
                    {
                        base.SerializeResourceInvariant(manager, ">>" + str + ".Parent", str4);
                    }
                    for (int i = 0; i < parent.Controls.Count; i++)
                    {
                        if (parent.Controls[i] == control)
                        {
                            base.SerializeResourceInvariant(manager, ">>" + str + ".ZOrder", i.ToString(CultureInfo.InvariantCulture));
                            return;
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        ///  This writes out our control hierarchy information if there is a resource manager available for us to write to.
        /// </summary>
        private void SerializeControlHierarchy(IDesignerSerializationManager manager, IDesignerHost host, object value)
        {
            Control control = value as Control;

            if (control != null)
            {
                // Object name
                string name;
                IMultitargetHelperService mthelperSvc = host.GetService(typeof(IMultitargetHelperService)) as IMultitargetHelperService;

                if (control == host.RootComponent)
                {
                    name = "$this";

                    // For the root component, we also take this as
                    // an opportunity to emit information for all non-visual components in the container too.
                    foreach (IComponent component in host.Container.Components)
                    {
                        // Skip controls
                        if (component is Control)
                        {
                            continue;
                        }

                        // Skip privately inherited components
                        if (TypeDescriptor.GetAttributes(component).Contains(InheritanceAttribute.InheritedReadOnly))
                        {
                            continue;
                        }

                        // Now emit the data
                        string componentName     = manager.GetName(component);
                        string componentTypeName = mthelperSvc is null?component.GetType().AssemblyQualifiedName : mthelperSvc.GetAssemblyQualifiedName(component.GetType());

                        if (componentName != null)
                        {
                            SerializeResourceInvariant(manager, ">>" + componentName + ".Name", componentName);
                            SerializeResourceInvariant(manager, ">>" + componentName + ".Type", componentTypeName);
                        }
                    }
                }
                else
                {
                    name = manager.GetName(value);

                    // if we get null back, this must be an unsited control
                    if (name is null)
                    {
                        Debug.Assert(!(value is IComponent) || ((IComponent)value).Site is null, "Unnamed, sited control in hierarchy");
                        return;
                    }
                }

                SerializeResourceInvariant(manager, ">>" + name + ".Name", manager.GetName(value));

                // Object type
                SerializeResourceInvariant(manager, ">>" + name + ".Type", mthelperSvc is null ? control.GetType().AssemblyQualifiedName : mthelperSvc.GetAssemblyQualifiedName(control.GetType()));

                // Parent
                Control parent = control.Parent;

                if (parent != null && parent.Site != null)
                {
                    string parentName;

                    if (parent == host.RootComponent)
                    {
                        parentName = "$this";
                    }
                    else
                    {
                        parentName = manager.GetName(parent);
                    }

                    if (parentName != null)
                    {
                        SerializeResourceInvariant(manager, ">>" + name + ".Parent", parentName);
                    }

                    // Z-Order
                    for (int i = 0; i < parent.Controls.Count; i++)
                    {
                        if (parent.Controls[i] == control)
                        {
                            SerializeResourceInvariant(manager, ">>" + name + ".ZOrder", i.ToString(CultureInfo.InvariantCulture));
                            break;
                        }
                    }
                }
            }
        }
        private void SerializeControlHierarchy(IDesignerSerializationManager manager, IDesignerHost host, object value)
        {
            Control control = value as Control;

            if (control != null)
            {
                IMultitargetHelperService multitargetHelperService = host.GetService(typeof(IMultitargetHelperService)) as IMultitargetHelperService;
                string text;
                if (control == host.RootComponent)
                {
                    text = "$this";
                    IEnumerator enumerator = host.Container.Components.GetEnumerator();
                    {
                        while (enumerator.MoveNext())
                        {
                            IComponent component = (IComponent)enumerator.Current;
                            if (!(component is Control) && !TypeDescriptor.GetAttributes(component).Contains(InheritanceAttribute.InheritedReadOnly))
                            {
                                string name   = manager.GetName(component);
                                string value2 = (multitargetHelperService == null) ? component.GetType().AssemblyQualifiedName : multitargetHelperService.GetAssemblyQualifiedName(component.GetType());
                                if (name != null)
                                {
                                    base.SerializeResourceInvariant(manager, ">>" + name + ".Name", name);
                                    base.SerializeResourceInvariant(manager, ">>" + name + ".Type", value2);
                                }
                            }
                        }
                        goto IL_107;
                    }
                }
                text = manager.GetName(value);
                if (text == null)
                {
                    return;
                }
IL_107:
                base.SerializeResourceInvariant(manager, ">>" + text + ".Name", manager.GetName(value));
                base.SerializeResourceInvariant(manager, ">>" + text + ".Type", (multitargetHelperService == null) ? control.GetType().AssemblyQualifiedName : multitargetHelperService.GetAssemblyQualifiedName(control.GetType()));
                Control parent = control.Parent;
                if (parent != null && parent.Site != null)
                {
                    string text2;
                    if (parent == host.RootComponent)
                    {
                        text2 = "$this";
                    }
                    else
                    {
                        text2 = manager.GetName(parent);
                    }
                    if (text2 != null)
                    {
                        base.SerializeResourceInvariant(manager, ">>" + text + ".Parent", text2);
                    }
                    for (int i = 0; i < parent.Controls.Count; i++)
                    {
                        if (parent.Controls[i] == control)
                        {
                            base.SerializeResourceInvariant(manager, ">>" + text + ".ZOrder", i.ToString(CultureInfo.InvariantCulture));
                            return;
                        }
                    }
                }
            }
        }