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.
ReadOnlyBindingList.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ReadOnlyBindingList.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>A readonly version of BindingList(Of T)</summary>
7//-----------------------------------------------------------------------
8using System;
9using Csla.Properties;
10
11namespace Csla.Core
12{
23 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming",
24 "CA1710:IdentifiersShouldHaveCorrectSuffix")]
25 [Serializable()]
26 public abstract class ReadOnlyBindingList<C> :
27 Core.ExtendedBindingList<C>, Core.IBusinessObject, Core.IReadOnlyBindingList
28 {
29 #region Identity
30
32 {
33 get { return 0; }
34 }
35
36 #endregion
37
38 private bool _isReadOnly = true;
39
48 public bool IsReadOnly
49 {
50 get { return IsReadOnlyCore; }
51 protected set { IsReadOnlyCore = value; }
52 }
53
58 protected virtual bool IsReadOnlyCore
59 {
60 get { return _isReadOnly; }
61 set { _isReadOnly = value; }
62 }
63
64 bool Core.IReadOnlyBindingList.IsReadOnly
65 {
66 get { return IsReadOnly; }
67 set { IsReadOnly = value; }
68 }
69
74 protected override void SetLoadListMode(bool enabled)
75 {
76 IsReadOnly = !enabled;
77 base.SetLoadListMode(enabled);
78 }
79
84 {
85 this.RaiseListChangedEvents = false;
86 AllowEdit = false;
87 AllowRemove = false;
88 AllowNew = false;
89 this.RaiseListChangedEvents = true;
90 }
91
95 protected override void ClearItems()
96 {
97 if (!IsReadOnly)
98 {
99 bool oldValue = AllowRemove;
100 AllowRemove = true;
101 base.ClearItems();
102 AllowRemove = oldValue;
103 }
104 else
105 throw new NotSupportedException(Resources.ClearInvalidException);
106 }
107
111#if NETFX_CORE || (ANDROID || IOS)
112 protected override void AddNewCore()
113 {
114 if (!IsReadOnly)
115 base.AddNewCore();
116 else
117 throw new NotSupportedException(Resources.InsertInvalidException);
118 }
119#else
120 protected override object AddNewCore()
121 {
122 if (!IsReadOnly)
123 return base.AddNewCore();
124 else
125 throw new NotSupportedException(Resources.InsertInvalidException);
126 }
127#endif
128
134 protected override void InsertItem(int index, C item)
135 {
136 if (!IsReadOnly)
137 {
138 base.InsertItem(index, item);
139 }
140 else
141 throw new NotSupportedException(Resources.InsertInvalidException);
142 }
143
149 protected override void RemoveItem(int index)
150 {
151 if (!IsReadOnly)
152 {
153 bool oldValue = AllowRemove;
154 AllowRemove = true;
155 base.RemoveItem(index);
156 AllowRemove = oldValue;
157 }
158 else
159 throw new NotSupportedException(Resources.RemoveInvalidException);
160 }
161
169 protected override void SetItem(int index, C item)
170 {
171 if (!IsReadOnly)
172 {
173 base.SetItem(index, item);
174 }
175 else
176 throw new NotSupportedException(Resources.ChangeInvalidException);
177 }
178
179#region ITrackStatus
180
185 public override bool IsBusy
186 {
187 get
188 {
189 // run through all the child objects
190 // and if any are dirty then then
191 // collection is dirty
192 foreach (C child in this)
193 {
194 INotifyBusy busy = child as INotifyBusy;
195 if (busy != null && busy.IsBusy)
196 return true;
197 }
198
199 return false;
200 }
201 }
202
203#endregion
204
205#region MobileFormatter
206
215 {
216 base.OnGetState(info);
217 info.AddValue("Csla.Core.ReadOnlyBindingList._isReadOnly", _isReadOnly);
218 }
219
228 {
229 base.OnSetState(info);
230 _isReadOnly = info.GetValue<bool>("Csla.Core.ReadOnlyBindingList._isReadOnly");
231 }
232
245 {
246 var old = IsReadOnly;
247 IsReadOnly = false;
248 base.OnSetChildren(info, formatter);
249 IsReadOnly = old;
250 }
251
252#endregion
253 }
254}
Extends BindingList of T by adding extra behaviors.
A readonly version of BindingList(Of T)
override void InsertItem(int index, C item)
Prevents insertion of items into the collection.
override object AddNewCore()
Prevents insertion of items into the collection.
override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info)
Override this method to retrieve your field values from the MobileFormatter serialzation stream.
override void SetItem(int index, C item)
Replaces the item at the specified index with the specified item if the collection is not in readonly...
override void OnGetState(Csla.Serialization.Mobile.SerializationInfo info)
Override this method to insert your field values into the MobileFormatter serialzation stream.
ReadOnlyBindingList()
Creates an instance of the object.
override void OnSetChildren(Csla.Serialization.Mobile.SerializationInfo info, Csla.Serialization.Mobile.MobileFormatter formatter)
Override this method to retrieve your child object references from the MobileFormatter serialzation s...
override void RemoveItem(int index)
Removes the item at the specified index if the collection is not in readonly mode.
override void SetLoadListMode(bool enabled)
Sets the LoadListMode for the collection
override bool IsBusy
Gets a value indicating whether this object or its child objects are busy.
override void ClearItems()
Prevents clearing the collection.
bool IsReadOnly
Gets or sets a value indicating whether the list is readonly.
virtual bool IsReadOnlyCore
Gets or sets a value indicating whether the list is readonly.
A strongly-typed resource class, for looking up localized strings, etc.
static string RemoveInvalidException
Looks up a localized string similar to Remove is an invalid operation.
static string InsertInvalidException
Looks up a localized string similar to Insert is an invalid operation.
static string ChangeInvalidException
Looks up a localized string similar to Changing an element is an invalid operation.
static string ClearInvalidException
Looks up a localized string similar to Clear is an invalid operation.
Serializes and deserializes objects at the field level.
Object containing the serialization data for a specific object.
This is the core interface implemented by all CSLA .NET base classes.
int Identity
Gets a value representing this object instance's unique identity value within the business object gra...
Interface defining an object that notifies when it is busy executing an asynchronous operation.
Definition: INotifyBusy.cs:17
bool IsBusy
Gets a value indicating whether the object, or any of the object's child objects, are busy running an...
Definition: INotifyBusy.cs:29
@ Serializable
Prevents updating or inserting until the transaction is complete.