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.
NameValueListBase.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="NameValueListBase.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>This is the base class from which readonly name/value</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.ComponentModel;
10using Csla.Properties;
11using Csla.Core;
13
14namespace Csla
15{
16
23 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
25 public abstract class NameValueListBase<K, V> :
26 Core.ReadOnlyBindingList<NameValueListBase<K, V>.NameValuePair>,
27 ICloneable, Core.IBusinessObject, Server.IDataPortalTarget
28 {
29
30 #region Core Implementation
31
37 public V Value(K key)
38 {
39 foreach (NameValuePair item in this)
40 if (item.Key.Equals(key))
41 return item.Value;
42 return default(V);
43 }
44
51 public K Key(V value)
52 {
53 foreach (NameValuePair item in this)
54 if (item.Value.Equals(value))
55 return item.Key;
56 return default(K);
57 }
58
64 public bool ContainsKey(K key)
65 {
66 foreach (NameValuePair item in this)
67 if (item.Key.Equals(key))
68 return true;
69 return false;
70 }
71
77 public bool ContainsValue(V value)
78 {
79 foreach (NameValuePair item in this)
80 if (item.Value.Equals(value))
81 return true;
82 return false;
83 }
84
94 {
95
96 foreach (NameValuePair item in this)
97 {
98 if (item != null && item.Value.Equals(value))
99 {
100 return item;
101 }
102 }
103 return null;
104
105 }
106
116 {
117
118 foreach (NameValuePair item in this)
119 {
120 if (item != null && item.Key.Equals(key))
121 {
122 return item;
123 }
124 }
125 return null;
126
127 }
128
129 #endregion
130
135 {
136 Initialize();
137 }
138
139 #region Initialize
140
146 protected virtual void Initialize()
147 { /* allows subclass to initialize events before any other activity occurs */ }
148
149 #endregion
150
151 #region NameValuePair class
152
156 [Serializable()]
158 {
159 private K _key;
160 private V _value;
161
162#if (ANDROID || IOS) || NETFX_CORE
166 public NameValuePair()
167 { }
168#else
169 private NameValuePair() { }
170#endif
171
175 public K Key
176 {
177 get { return _key; }
178 }
179
183 public V Value
184 {
185 get { return _value; }
186 }
187
193 public NameValuePair(K key, V value)
194 {
195 _key = key;
196 _value = value;
197 }
198
203 public override string ToString()
204 {
205 return _value.ToString();
206 }
207
214 protected override void OnGetState(SerializationInfo info, StateMode mode)
215 {
216 base.OnGetState(info, mode);
217 info.AddValue("NameValuePair._key", _key);
218 info.AddValue("NameValuePair._value", _value);
219 }
220
227 protected override void OnSetState(SerializationInfo info, StateMode mode)
228 {
229 base.OnSetState(info, mode);
230 _key = info.GetValue<K>("NameValuePair._key");
231 _value = info.GetValue<V>("NameValuePair._value");
232 }
233
234 }
235
236 #endregion
237
238 #region ICloneable
239
240 object ICloneable.Clone()
241 {
242 return GetClone();
243 }
244
249 [EditorBrowsable(EditorBrowsableState.Advanced)]
250 protected virtual object GetClone()
251 {
252 return Core.ObjectCloner.Clone(this);
253 }
254
259 {
261 }
262
263 #endregion
264
265 #region Data Access
266
267 private void DataPortal_Update()
268 {
269 throw new NotSupportedException(Resources.UpdateNotSupportedException);
270 }
271
272 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "criteria")]
273 [Delete]
274 private void DataPortal_Delete(object criteria)
275 {
276 throw new NotSupportedException(Resources.DeleteNotSupportedException);
277 }
278
284 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
285 [EditorBrowsable(EditorBrowsableState.Advanced)]
287 {
288
289 }
290
296 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
297 [EditorBrowsable(EditorBrowsableState.Advanced)]
299 {
300
301 }
302
309 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
310 [EditorBrowsable(EditorBrowsableState.Advanced)]
311 protected virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
312 {
313
314 }
315
316 #endregion
317
318 #region IDataPortalTarget Members
319
320 void Csla.Server.IDataPortalTarget.CheckRules()
321 { }
322
323 void Csla.Server.IDataPortalTarget.MarkAsChild()
324 { }
325
326 void Csla.Server.IDataPortalTarget.MarkNew()
327 { }
328
329 void Csla.Server.IDataPortalTarget.MarkOld()
330 { }
331
332 void Csla.Server.IDataPortalTarget.DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
333 {
335 }
336
337 void Csla.Server.IDataPortalTarget.DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
338 {
340 }
341
342 void Csla.Server.IDataPortalTarget.DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
343 {
345 }
346
347 void Csla.Server.IDataPortalTarget.Child_OnDataPortalInvoke(DataPortalEventArgs e)
348 { }
349
350 void Csla.Server.IDataPortalTarget.Child_OnDataPortalInvokeComplete(DataPortalEventArgs e)
351 { }
352
353 void Csla.Server.IDataPortalTarget.Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
354 { }
355
356 #endregion
357 }
358}
Inherit from this base class to easily create a serializable class.
Definition: MobileObject.cs:20
A readonly version of BindingList(Of T)
Provides information about the DataPortal call.
Contains a key and value pair.
override string ToString()
Returns a string representation of the value for this item.
NameValuePair(K key, V value)
Creates an instance of the object.
V Value
The Value corresponding to the key/name.
override void OnGetState(SerializationInfo info, StateMode mode)
Override this method to manually get custom field values from the serialization stream.
override void OnSetState(SerializationInfo info, StateMode mode)
Override this method to manually set custom field values into the serialization stream.
This is the base class from which readonly name/value collections should be derived.
bool ContainsValue(V value)
Gets a value indicating whether the list contains the specified value.
virtual void Initialize()
Override this method to set up event handlers so user code in a partial class can respond to events r...
NameValuePair GetItemByValue(V value)
Get the item for the first matching value in the collection.
NameValueListBase()
Creates an instance of the object.
K Key(V value)
Returns the key corresponding to the first occurance of the specified value in the list.
virtual object GetClone()
Creates a clone of the object.
NameValuePair GetItemByKey(K key)
Get the item for the first matching key in the collection.
virtual void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
Called by the server-side DataPortal after calling the requested DataPortal_XYZ method.
V Value(K key)
Returns the value corresponding to the specified key.
NameValueListBase< K, V > Clone()
Creates a clone of the object.
virtual void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
Called by the server-side DataPortal prior to calling the requested DataPortal_XYZ method.
virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
Called by the server-side DataPortal if an exception occurs during data access.
bool ContainsKey(K key)
Gets a value indicating whether the list contains the specified key.
A strongly-typed resource class, for looking up localized strings, etc.
static string DeleteNotSupportedException
Looks up a localized string similar to Invalid operation - delete not allowed.
static string UpdateNotSupportedException
Looks up a localized string similar to Invalid operation - update not allowed.
Object containing the serialization data for a specific object.
void AddValue(string name, object value)
Adds a value to the serialization stream.
This is the core interface implemented by all CSLA .NET base classes.
StateMode
Indicates the reason the MobileFormatter functionality has been invoked.
Definition: StateMode.cs:20
@ Serializable
Prevents updating or inserting until the transaction is complete.