您可以將對象保存到Visual Studio中的settings.settings文件中嗎?如果是這樣如何?我認爲你可以讓你的對象可序列化並且它應該持久化,但是我不知道我是否正確地做了這件事,即當我試圖獲取對象時,它總是空的。如何將對象保存到Visual Studio中的fooSettings.settings文件中?
下面是代碼:
[Serializable()]
[XmlRoot(ElementName = "LayerTCA", IsNullable = false, Namespace = "http://somesite.com")]
public class LayerTCA
{
//This is a COM object so I don't want to serialize this.
IFeatureClass featureClass;
string fullName;
string basicName;
public LayerTCA()
{
}
public LayerTCA(IFeatureClass featureClass)
{
FeatureClass = featureClass;
}
public IFeatureClass FeatureClass
{
get { return featureClass; }
set
{
featureClass = value;
fullName = featureClass.AliasName;
basicName = StringHelper.StringAfterLastFullStop(fullName);
}
}
[XmlAttribute(AttributeName = "BasicName")]
public string BasicName
{
get { return basicName; }
set { basicName = value; }
}
[XmlAttribute(AttributeName = "FullName")]
public string FullName
{
get { return fullName; }
set { fullName = value; }
}
public override string ToString()
{
return FullName;
}
}
你可以添加序列化/反序列化代碼嗎? – Rox 2010-06-16 11:20:32
它只是靜態調用fooSettings.settings來保存對象,即 var layerTCA = new LayerTCA(); fooSettings.settings.Default.myLayerTCA = layerTCA; 然後反過來檢索。 – Vidar 2010-06-16 12:45:43
這裏一點更新:我嘗試了一些測試,似乎你可以在Settings.setting文件只要保存一個類你自己的,因爲它沒有像它一個COM變量。必須有某種方法來對FeatureClass進行賦值,以便在序列化時忽略它。 – Vidar 2010-06-16 15:24:06