CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
MobileList.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="MobileList.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Implements a list that is serializable using</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
13using serialization = System.Runtime.Serialization;
14using System.IO;
15using System.Reflection;
16using Csla.Reflection;
17
18namespace Csla.Core
19{
27 [Serializable]
28 public class MobileList<T> : List<T>, IMobileObject
29 {
33 public MobileList() : base() { }
38 public MobileList(int capacity) : base(capacity) { }
43 public MobileList(IEnumerable<T> collection) : base(collection) { }
44
45 #region IMobileObject Members
46
48 {
49 OnGetChildren(info, formatter);
50 }
51
53 {
54 OnGetState(info);
55 }
56
62 protected virtual void OnGetState(SerializationInfo info)
63 {
64 }
65
66 private const string _valuePrefix = "v";
67
74 protected virtual void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
75 {
76 bool mobileChildren = typeof(IMobileObject).IsAssignableFrom(typeof(T));
77 int count = 0;
78 foreach (T child in this)
79 {
80 if (mobileChildren)
81 {
82 SerializationInfo si = formatter.SerializeObject(child);
83 info.AddChild(_valuePrefix + count, si.ReferenceId);
84 }
85 else
86 {
87 info.AddValue(_valuePrefix + count, child);
88 }
89 count++;
90 }
91 info.AddValue("count", count);
92 }
93
95 {
96 OnSetState(info);
97 }
98
100 {
101 OnSetChildren(info, formatter);
102 }
103
109 protected virtual void OnSetState(SerializationInfo info) { }
110
117 protected virtual void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
118 {
119 bool mobileChildren = typeof(IMobileObject).IsAssignableFrom(typeof(T));
120 int count = info.GetValue<int>("count");
121
122 for (int index = 0; index < count; index++)
123 {
124 T value;
125 if (mobileChildren)
126 value = (T)formatter.GetObject(info.Children[_valuePrefix + index].ReferenceId);
127 else
128 value = info.GetValue<T>(_valuePrefix + index);
129
130 Add(value);
131 }
132 }
133
134 #endregion
135 }
136}
System.Runtime.Serialization serialization
Definition: MobileList.cs:13
Implements a list that is serializable using the SerializationFormatterFactory.GetFormatter().
Definition: MobileList.cs:29
virtual void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
Override this method to manually serialize child objects contained within the current object.
Definition: MobileList.cs:74
MobileList(IEnumerable< T > collection)
Creates an instance of the type.
Definition: MobileList.cs:43
MobileList(int capacity)
Creates an instance of the type.
Definition: MobileList.cs:38
virtual void OnSetState(SerializationInfo info)
Override this method to retrieve extra field values to the serialization stream.
Definition: MobileList.cs:109
MobileList()
Creates an instance of the type.
Definition: MobileList.cs:33
virtual void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
Override this method to manually deserialize child objects from data in the serialization stream.
Definition: MobileList.cs:117
virtual void OnGetState(SerializationInfo info)
Override this method to add extra field values to the serialization stream.
Definition: MobileList.cs:62
Serializes and deserializes objects at the field level.
IMobileObject GetObject(int referenceId)
Gets a deserialized object based on the object's reference id within the serialization stream.
SerializationInfo SerializeObject(object obj)
Serializes an object into a SerializationInfo object.
Object containing the serialization data for a specific object.
int ReferenceId
Reference number for this object.
Dictionary< string, ChildData > Children
Dictionary containing child reference data.
void AddChild(string name, int referenceId)
Adds a child to the list of child references.
void AddValue(string name, object value)
Adds a value to the serialization stream.
Interface to be implemented by any object that supports serialization by the SerializationFormatterFa...
void GetChildren(SerializationInfo info, MobileFormatter formatter)
Method called by MobileFormatter when an object should serialize its child references.
void GetState(SerializationInfo info)
Method called by MobileFormatter when an object should serialize its data.
void SetChildren(SerializationInfo info, MobileFormatter formatter)
Method called by MobileFormatter when an object should deserialize its child references.
void SetState(SerializationInfo info)
Method called by MobileFormatter when an object should be deserialized.