C# 类序列化时遇到问题
将此类序列化为属性集合时遇到问题,它是另一个属性集合的一部分,并在其中列出为:C# 类序列化时遇到问题,c#,serialization,propertygrid,C#,Serialization,Propertygrid,将此类序列化为属性集合时遇到问题,它是另一个属性集合的一部分,并在其中列出为: `[PropertyTab("AddCellRules"), Browsable(true), Description("Add Cell Rules"), Category("ColumnProperties"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public Coll
`[PropertyTab("AddCellRules"),
Browsable(true),
Description("Add Cell Rules"), Category("ColumnProperties"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Collection<CellRules> CellRules { get; set; }`
实际等级:
`[Serializable]
public class CellRules
{
private bool compliment;
private Color backColor;
[PropertyTab("AddExtendedCellProperty")]
[Browsable(true)]
[Description("BackgroundColor"), Category("CellProperties"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Color BackgroundColor
{
get
{
return backColor;
}
set
{
if (compliment)
{
ForeColor = SetForeColor(value);
}
backColor = value;
}
}
[PropertyTab("AddExtendedCellProperty")]
[Browsable(true)]
[Description("ComplimentBackColor"), Category("CellProperties"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public bool ComplimentBackColor {
get
{
return compliment;
}
set
{
if (value)
{
ForeColor = SetForeColor(BackgroundColor);
}
compliment = value;
}
}
[PropertyTab("AddExtendedCellProperty")]
[Browsable(true)]
[Description("ForeColor"), Category("CellProperties")]
public Color ForeColor { get; set; }
[PropertyTab("AddExtendedCellProperty")]
[Browsable(true)]
[Description("FontType"), Category("CellProperties"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Font FontType { get; set; }
[PropertyTab("AddExtendedCellProperty")]
[Browsable(true)]
[Description("FontStyles"), Category("CellProperties"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public FontStyle FontStyles { get; set; }
[PropertyTab("AddExtendedCellProperty")]
[Browsable(true)]
[Description("TriggerOnData"), Category("CellProperties")]
public bool TriggerOnData { get; set; }
[PropertyTab("AddExtendedCellProperty")]
[Browsable(true)]
[Description("DataTrigger"), Category("CellProperties")]
public String DataTrigger { get; set; }
[PropertyTab("AddExtendedCellProperty")]
[Browsable(true)]
[Description("TrggerOperator"), Category("CellProperties")]
public Operator TrggerOperator { get; set; }
[PropertyTab("AddExtendedColumnProperty")]
[Browsable(true)]
[Description("Pivot"), Category("ColumnProperties")]
public PivotTypes Pivot { get; set; }
[PropertyTab("AddExtendedColumnProperty")]
[Browsable(true)]
[Description("InitialPivot"), Category("ColumnProperties")]
public bool InitialPivot { get; set; }
[PropertyTab("AddExtendedColumnProperty")]
[Browsable(true)]
[Description("Alignment"), Category("ColumnProperties")]
public DataGridViewContentAlignment ContentAlignment { get; set; }
public CellRules()
{
Pivot = PivotTypes.none;
BackgroundColor = Cell_GlobalVars.backgroundColor;
ForeColor = Cell_GlobalVars.foreColor;
FontType = Cell_GlobalVars.fontType;
FontStyles = Cell_GlobalVars.fontStyles;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
private Color SetForeColor(Color Colors)
{
Color result = Color.Black;
double Brightness = Math.Sqrt(.299 * Math.Pow(Colors.R, 2) + .587 * Math.Pow(Colors.G, 2) + .114 * Math.Pow(Colors.B, 2));
if (Brightness < 130)
result = Color.White;
return result;
}
}`
我确实运行了serTool,没有错误,没有任何想法?..这是什么语言?c,很抱歉,我假设它是obivousI放置的[DesignerSerializationVisibilityDesignerSerializationVisibility.Content在所有成员上,现在它将作为控件上的属性序列化,但是当它是属性的属性时,它仍然不会序列化。是否添加了一些装饰程序来实现这一点?问题已解决,需要将结果应用于私有成员这是在声明中实例化的。我之前所做的是使用setter在构造函数中实例化。如果不是在嵌套方法中,这将起作用,这就是为什么它作为控件的属性而不是UI编辑器中的属性起作用。。。