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.
ReadOnlyObservableBindingList.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ReadOnlyObservableBindingList.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 ObservableBindingList.</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Collections.Specialized;
11using System.Linq;
12using System.Text;
13using Csla.Properties;
14
15namespace Csla.Core
16{
29 Core.IReadOnlyBindingList
30 {
36 {
37 AllowEdit = false;
38 AllowNew = false;
39 AllowRemove = false;
40
41 this.CollectionChanged += (o, e) =>
42 {
43 if (IsReadOnly)
44 throw new NotSupportedException(Resources.ChangeReadOnlyListInvalid);
45 };
46 }
47
52 protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
53 {
54 if (IsReadOnly)
55 throw new NotSupportedException(Resources.ChangeReadOnlyListInvalid);
56 base.OnCollectionChanged(e);
57 }
58
59 #region IsReadOnly
60
61 private bool _isReadOnly = true;
62
71 public bool IsReadOnly
72 {
73 get { return _isReadOnly; }
74 protected set { _isReadOnly = value; }
75 }
76
77 bool Core.IReadOnlyBindingList.IsReadOnly
78 {
79 get { return IsReadOnly; }
80 set { IsReadOnly = value; }
81 }
82
87 protected override void SetLoadListMode(bool enabled)
88 {
89 IsReadOnly = !enabled;
90 base.SetLoadListMode(enabled);
91 }
92
93 #endregion
94
95 #region MobileFormatter
96
105 {
106 base.OnGetState(info);
107 info.AddValue("Csla.Core.ReadOnlyBindingList._isReadOnly", _isReadOnly);
108 }
109
118 {
119 base.OnSetState(info);
120 _isReadOnly = info.GetValue<bool>("Csla.Core.ReadOnlyBindingList._isReadOnly");
121 }
122
135 {
136 var old = IsReadOnly;
137 IsReadOnly = false;
138 base.OnSetChildren(info, formatter);
139 IsReadOnly = old;
140 }
141
142 #endregion
143 }
144}
Extends ObservableCollection with behaviors required by CSLA .NET collections.
bool AllowRemove
Gets or sets a value indicating whether data binding can automatically remove items from this collect...
bool AllowEdit
Gets or sets a value indicating whether data binding can automatically edit items in this collection.
bool AllowNew
Gets or sets a value indicating whether data binding can automatically add new items to this collecti...
A readonly version of ObservableBindingList.
override void SetLoadListMode(bool enabled)
Sets the LoadListMode for the collection
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 OnGetState(Csla.Serialization.Mobile.SerializationInfo info)
Override this method to insert your field values into the MobileFormatter serialzation stream.
ReadOnlyObservableBindingList()
Creates an instance of the type.
bool IsReadOnly
Gets or sets a value indicating whether the list is readonly.
override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Method invoked when collection is changed.
override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info)
Override this method to retrieve your field values from the MobileFormatter serialzation stream.
A strongly-typed resource class, for looking up localized strings, etc.
static string ChangeReadOnlyListInvalid
Looks up a localized string similar to Can not change a read-only list or collection.
Serializes and deserializes objects at the field level.
Object containing the serialization data for a specific object.
@ Serializable
Prevents updating or inserting until the transaction is complete.