CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
MobileObservableCollection.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="MobileObservableCollection.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Inherit from this base class to easily</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.ComponentModel;
10using System.Collections.Generic;
12using Csla.Properties;
13using System.Diagnostics;
14
15namespace Csla.Core
16{
24#if TESTING
25 [System.Diagnostics.DebuggerStepThrough]
26#endif
28 public class MobileObservableCollection<T> : System.Collections.ObjectModel.ObservableCollection<T>,
30 {
31 #region LoadListMode
32
33 [NonSerialized]
34 [NotUndoable]
35 private LoadListModeObject _loadListModeObject = null;
36
43 [DebuggerBrowsable(DebuggerBrowsableState.Never)]
45 {
46 get
47 {
48 if (_loadListModeObject == null)
49 _loadListModeObject = new LoadListModeObject(this);
50 return _loadListModeObject;
51 }
52 }
53 void IMobileList.SetLoadListMode(bool enabled)
54 {
55 _loadListModeObject = null;
56 SetLoadListMode(enabled);
57 }
58
63 protected virtual void SetLoadListMode(bool enabled)
64 {
65 }
66
73 [EditorBrowsable(EditorBrowsableState.Never)]
74#pragma warning disable CA1063 // Implement IDisposable Correctly
75 protected class LoadListModeObject : IDisposable
76#pragma warning restore CA1063 // Implement IDisposable Correctly
77 {
78 private readonly IMobileList _target;
84 {
85 _target = target;
86 _target.SetLoadListMode(true);
87 }
88
92#pragma warning disable CA1063 // Implement IDisposable Correctly
93 public void Dispose()
94#pragma warning restore CA1063 // Implement IDisposable Correctly
95 {
96 _target.SetLoadListMode(false);
97 GC.SuppressFinalize(this);
98 }
99 }
100
101 #endregion
102
103 #region IMobileObject Members
104
106 {
107 OnGetChildren(info, formatter);
108 }
109
111 {
112 OnGetState(info);
113 }
114
120 [EditorBrowsable(EditorBrowsableState.Advanced)]
121 protected virtual void OnGetState(SerializationInfo info)
122 { }
123
130 [EditorBrowsable(EditorBrowsableState.Advanced)]
131 protected virtual void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
132 {
133 if (!typeof(IMobileObject).IsAssignableFrom(typeof(T)))
134 throw new InvalidOperationException(Resources.CannotSerializeCollectionsNotOfIMobileObject);
135
136 List<int> references = new List<int>();
137 for (int x = 0; x < this.Count; x++)
138 {
139 T child = this[x];
140 if (child != null)
141 {
142 SerializationInfo childInfo = formatter.SerializeObject(child);
143 references.Add(childInfo.ReferenceId);
144 }
145 }
146 if (references.Count > 0)
147 info.AddValue("$list", references);
148 }
149
151 {
152 OnSetState(info);
153 }
154
156 {
157 OnSetChildren(info, formatter);
158 }
159
165 [EditorBrowsable(EditorBrowsableState.Advanced)]
166 protected virtual void OnSetState(SerializationInfo info)
167 { }
168
175 [EditorBrowsable(EditorBrowsableState.Advanced)]
176 protected virtual void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
177 {
178 if (!typeof(IMobileObject).IsAssignableFrom(typeof(T)))
179 throw new InvalidOperationException(Resources.CannotSerializeCollectionsNotOfIMobileObject);
180
181 if (info.Values.ContainsKey("$list"))
182 {
183 List<int> references = (List<int>)info.Values["$list"].Value;
184 foreach (int reference in references)
185 {
186 T child = (T)formatter.GetObject(reference);
187 this.Add(child);
188 }
189 }
190 }
191
192 #endregion
193 }
194}
Class that allows setting of property values on current business object without raising PropertyChang...
LoadListModeObject(IMobileList target)
Create instance of type
Inherit from this base class to easily create a serializable list class.
virtual void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
Override this method to get custom child object values from the serialization stream.
virtual void OnSetState(SerializationInfo info)
Override this method to set custom field values into the serialization stream.
virtual void OnGetState(SerializationInfo info)
Override this method to get custom field values from the serialization stream.
virtual void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
Override this method to set custom child object values into the serialization stream.
LoadListModeObject LoadListMode
By wrapping this property inside Using block you can set property values on current business object w...
virtual void SetLoadListMode(bool enabled)
Sets the load list mode for the list
A strongly-typed resource class, for looking up localized strings, etc.
static string CannotSerializeCollectionsNotOfIMobileObject
Looks up a localized string similar to Cannot serialize collections not of type IMobileObject.
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.
Dictionary< string, FieldData > Values
Dictionary containg field data.
int ReferenceId
Reference number for this object.
void AddValue(string name, object value)
Adds a value to the serialization stream.
Extension of IMobileObject for list types
Definition: IMobileList.cs:14
void SetLoadListMode(bool enabled)
Sets the LoadListMode for the collection
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.
@ Serializable
Prevents updating or inserting until the transaction is complete.