IsolatedStorage에 다른 객체를 저장해야하며이를 수행하기 위해 IsolatedStorageSettings 클래스를 사용하고 있습니다. 이러한 객체 중 일부는 잘 저장되고 검색되는 기본 유형입니다. 하지만 그들 중 일부는 사용자 정의 클래스 인스턴스이며 그들은 잘 저장하지만, 내가 그들을 검색하려고하면 초기 값으로 인스턴스를 얻을. 사용자 정의 클래스 인스턴스를 IsolatedStorage에 저장하고 검색하려면 어떻게해야합니까?Silverlight의 IsolatedStorage에 사용자 정의 클래스 인스턴스 저장
필 샌들러, 그렇게 생각합니다. 하지만 어떤 유형의 직렬화가 고립 된 저장소를 사용하는지 모르겠다. 그래서 나는 내 클래스를 직렬화 할 수있는 방법을 모른다. 비공개 필드도 저장해야합니다.
public class ExtentHistory : INotifyPropertyChanged
{
private const int Capacity = 20;
private List<Envelope> _extents;
private int _currentPosition;
public event PropertyChangedEventHandler PropertyChanged;
public int ItemsCount
{
get { return _extents.Count; }
}
public bool CanStepBack
{
get { return _currentPosition > 0; }
}
public bool CanStepForward
{
get { return _currentPosition < _extents.Count - 1; }
}
public Envelope CurrentExtent
{
get { return (_extents.Count > 0) ? _extents[_currentPosition] : null; }
}
public ExtentHistory()
{
_extents = new List<Envelope>();
_currentPosition = -1;
}
public void Add(Envelope extent)
{
if (_extents.Count > Capacity)
{
_extents.RemoveAt(0);
_currentPosition--;
}
_currentPosition++;
while (_extents.Count > _currentPosition)
{
_extents.RemoveAt(_currentPosition);
}
_extents.Add(extent);
}
public void StepBack()
{
if (CanStepBack)
{
_currentPosition--;
NotifyPropertyChanged("CurrentExtent");
}
}
public void StepForward()
{
if (CanStepForward)
{
_currentPosition++;
NotifyPropertyChanged("CurrentExtent");
}
}
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
그리고 여기에 저장하고 검색하는 기능은 다음과 같습니다 : 여기 사용자 정의 클래스의 코드 내가 추가 수동으로 모든 객체를 직렬화하고 싶지 않은
private IsolatedStorageSettings _storage;
public void Store(string key, object value)
{
if (!_storage.Contains(key))
{
_storage.Add(key, value);
}
else
{
_storage[key] = value;
}
}
public object Retrieve(string key)
{
return _storage.Contains(key) ? _storage[key] : null;
}
는, 내가 만들고 싶어 가능한 경우 격리 된 저장소에 저장하기 위해 기본적으로 직렬화 가능한 사용자 정의 클래스입니다.
제발, 내 편집 된 게시물을보세요 –
내 대답이 업데이트되었습니다. –
답장을 보내 주셔서 감사합니다. 그것은 해결책입니다. –