用xml保存c#数据 [英] save c# data with xml

查看:114
本文介绍了用xml保存c#数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中定义了用户控件,并且它们具有属性.单击保存"按钮时,我将其属性保存为xml.
请帮助我
我的代码是这样的:

i define user control in my project and they have property.i save their property with xml when click save button.
please help me
my code like this:

private string condition;
public string Condition
{
    get { return condition; }
    set { condition = value; }
}
private bool checkwhile;

public bool CheckWhile
{
    get { return checkwhile; }
    set { checkwhile = value; }
}
private bool checkfor;

public bool CheckFor
{
    get { return checkfor; }
    set { checkfor = value; }
}

public int Iteration
{
    get { return iteration; }
    set { iteration = value; }
}

推荐答案

使用数据合约.将适当的属性[DataConract][DataMembers]添加到您的类型和需要成为合同一部分的成员(某些或全部成员可以是私有的,没关系),并使用DataContractSerializerDataContractJsonSerializer. br/>
有关更多详细信息,请参见:
http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

另请参阅我过去的解决方案:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [反序列化json字符串数组 [
Use Data Contract. Add appropriate attributes [DataConract] and [DataMembers] to your type and members you need to be part of the contract (some or all of the members can be private, it does not matter) and use DataContractSerializer or DataContractJsonSerializer.

For further detail, see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

See also my past solutions:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^],
deseralize a json string array[^].

—SA


这篇关于用xml保存c#数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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