在DesignTime中序列化组件属性 [英] Serialize component properties in DesignTime

查看:78
本文介绍了在DesignTime中序列化组件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么一些在设计时正常工作的属性需要使用atrrribute [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]进行序列化,直到在初始化component()表单中生成它,而有些则不需要(具有Types(int,Color,Font, ...))?


why some of propertis for work correctly in designtime need to serializing with atrribute [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] until generated in initializationcomponent() a Form, but some do not need(propertie with Types(int,Color,Font,...))?


        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [System.ComponentModel.TypeConverter(typeof(ExpandableObjectConverter))]
        public DataGridViewColumnCollection GridColumns
        {
            set
            {   
                _GridColumns = value;             // need serializeing
            }

            get
            {
                if (_GridColumns == null)
                    _GridColumns = new DataGridViewColumnCollection(new DataGridView());
                return _GridColumns;
            }

        }

---------------------------------------------------------------------

public int Width
        {
            set
            {   
                _Width = value;                  //Does not need serializeing
            }

            get
            {
                if (_Width == null)
                    _Width = new DataGridViewColumnCollection(new DataGridView());
                return  _Width;
            }

        }

推荐答案

如果类型本身已经具有Serializable属性,则会自动调用序列化程序.在您的示例中,System.Int32是由框架序列化的基本类型(框架中定义的Serializable属性).另一方面,DataGridViewColumnCollection没有定义属性,因此您必须手动定义行为.
If the type itself already has the Serializable attribute the serializer is called automatically. In your example System.Int32 is a basic type which is serialized by the framework (Serializable attribute defined in the framework). On the other hand DataGridViewColumnCollection doesn''t have the attribute defined so you have to manually define the behaviour.


这篇关于在DesignTime中序列化组件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆