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.
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,
29 {
33 protected ApplicationContext ApplicationContext { get; private set; }
34 ApplicationContext Core.IUseApplicationContext.ApplicationContext
35 {
36 get => ApplicationContext;
37 set
38 {
39 ApplicationContext = value;
40 Initialize();
41 }
42 }
43
44 #region Core Implementation
45
51 public V Value(K key)
52 {
53 foreach (NameValuePair item in this)
54 if (item.Key.Equals(key))
55 return item.Value;
56 return default(V);
57 }
58
65 public K Key(V value)
66 {
67 foreach (NameValuePair item in this)
68 if (item.Value.Equals(value))
69 return item.Key;
70 return default(K);
71 }
72
78 public bool ContainsKey(K key)
79 {
80 foreach (NameValuePair item in this)
81 if (item.Key.Equals(key))
82 return true;
83 return false;
84 }
85
91 public bool ContainsValue(V value)
92 {
93 foreach (NameValuePair item in this)
94 if (item.Value.Equals(value))
95 return true;
96 return false;
97 }
98
108 {
109
110 foreach (NameValuePair item in this)
111 {
112 if (item != null && item.Value.Equals(value))
113 {
114 return item;
115 }
116 }
117 return null;
118
119 }
120
130 {
131
132 foreach (NameValuePair item in this)
133 {
134 if (item != null && item.Key.Equals(key))
135 {
136 return item;
137 }
138 }
139 return null;
140
141 }
142
143 #endregion
144
149 { }
150
151 #region Initialize
152
158 protected virtual void Initialize()
159 { /* allows subclass to initialize events before any other activity occurs */ }
160
161 #endregion
162
163 #region NameValuePair class
164
168 [Serializable()]
170 {
171 private K _key;
172 private V _value;
173
174#if (ANDROID || IOS) || NETFX_CORE
178 public NameValuePair()
179 { }
180#else
181 private NameValuePair() { }
182#endif
183
187 public K Key
188 {
189 get { return _key; }
190 }
191
195 public V Value
196 {
197 get { return _value; }
198 }
199
205 public NameValuePair(K key, V value)
206 {
207 _key = key;
208 _value = value;
209 }
210
215 public override string ToString()
216 {
217 return _value.ToString();
218 }
219
226 protected override void OnGetState(SerializationInfo info, StateMode mode)
227 {
228 base.OnGetState(info, mode);
229 info.AddValue("NameValuePair._key", _key);
230 info.AddValue("NameValuePair._value", _value);
231 }
232
239 protected override void OnSetState(SerializationInfo info, StateMode mode)
240 {
241 base.OnSetState(info, mode);
242 _key = info.GetValue<K>("NameValuePair._key");
243 _value = info.GetValue<V>("NameValuePair._value");
244 }
245
246 }
247
248 #endregion
249
250 #region ICloneable
251
252 object ICloneable.Clone()
253 {
254 return GetClone();
255 }
256
261 [EditorBrowsable(EditorBrowsableState.Advanced)]
262 protected virtual object GetClone()
263 {
264 return Core.ObjectCloner.GetInstance(ApplicationContext).Clone(this);
265 }
266
271 {
273 }
274
275 #endregion
276
277 #region Data Access
278
279 private void DataPortal_Update()
280 {
281 throw new NotSupportedException(Resources.UpdateNotSupportedException);
282 }
283
284 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "criteria")]
285 [Delete]
286 private void DataPortal_Delete(object criteria)
287 {
288 throw new NotSupportedException(Resources.DeleteNotSupportedException);
289 }
290
296 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
297 [EditorBrowsable(EditorBrowsableState.Advanced)]
299 {
300
301 }
302
308 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
309 [EditorBrowsable(EditorBrowsableState.Advanced)]
311 {
312
313 }
314
321 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
322 [EditorBrowsable(EditorBrowsableState.Advanced)]
323 protected virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
324 {
325
326 }
327
328 #endregion
329
330 #region IDataPortalTarget Members
331
332 void Csla.Server.IDataPortalTarget.CheckRules()
333 { }
334
335 void Csla.Server.IDataPortalTarget.MarkAsChild()
336 { }
337
338 void Csla.Server.IDataPortalTarget.MarkNew()
339 { }
340
341 void Csla.Server.IDataPortalTarget.MarkOld()
342 { }
343
344 void Csla.Server.IDataPortalTarget.DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
345 {
347 }
348
349 void Csla.Server.IDataPortalTarget.DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
350 {
352 }
353
354 void Csla.Server.IDataPortalTarget.DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
355 {
357 }
358
359 void Csla.Server.IDataPortalTarget.Child_OnDataPortalInvoke(DataPortalEventArgs e)
360 { }
361
362 void Csla.Server.IDataPortalTarget.Child_OnDataPortalInvokeComplete(DataPortalEventArgs e)
363 { }
364
365 void Csla.Server.IDataPortalTarget.Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
366 { }
367
368 #endregion
369 }
370}
Provides consistent context information between the client and server DataPortal objects.
ApplicationContext(ApplicationContextAccessor applicationContextAccessor)
Creates a new instance of the type
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 type.
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 type.
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.
ApplicationContext ApplicationContext
Gets the current ApplicationContext
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.
Implement if a class requires access to the CSLA ApplicationContext type.
StateMode
Indicates the reason the MobileFormatter functionality has been invoked.
Definition: StateMode.cs:20
@ Serializable
Prevents updating or inserting until the transaction is complete.