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.
FieldDataList.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="FieldDataList.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Runtime.Serialization;
11
13{
15#if (ANDROID || IOS) || NETFX_CORE
16 internal class FieldDataList : Csla.Core.MobileObject, Csla.Serialization.Mobile.ISerializationNotification
17#else
18 internal class FieldDataList : ISerializable
19#endif
20 {
21 [NonSerialized()]
22 private Dictionary<string, int> _fieldIndex = new Dictionary<string, int>();
23#if (ANDROID || IOS) || NETFX_CORE
24 private Csla.Core.MobileBindingList<IFieldData> _fields = new Csla.Core.MobileBindingList<IFieldData>();
25#else
26 private List<IFieldData> _fields = new List<IFieldData>();
27#endif
28
29 public FieldDataList()
30 { /* required due to serialization ctor */ }
31
32 public bool TryGetValue(string key, out IFieldData result)
33 {
34 int index;
35 if (_fieldIndex.TryGetValue(key, out index))
36 {
37 result = _fields[index];
38 return true;
39 }
40 else
41 {
42 result = null;
43 return false;
44 }
45 }
46
47 public bool ContainsKey(string key)
48 {
49 return _fieldIndex.ContainsKey(key);
50 }
51
52 public IFieldData GetValue(string key)
53 {
54 return _fields[_fieldIndex[key]];
55 }
56
57 public void Add(string key, IFieldData value)
58 {
59 _fields.Add(value);
60 _fieldIndex.Add(key, _fields.Count - 1);
61 }
62
63 internal string FindPropertyName(object value)
64 {
65 foreach (var item in _fields)
66 if (ReferenceEquals(item.Value, value))
67 return item.Name;
68 return null;
69 }
70
71#if (ANDROID || IOS) || NETFX_CORE
72 public Csla.Core.MobileBindingList<IFieldData> GetFieldDataList()
73 {
74 return _fields;
75 }
76#else
77 public List<IFieldData> GetFieldDataList()
78 {
79 return _fields;
80 }
81#endif
82
83#if (ANDROID || IOS) || NETFX_CORE
84 #region ISerializationNotification Members
85
87 {
88 RebuildIndex();
89 }
90
91 private void RebuildIndex()
92 {
93 var position = 0;
94 foreach (IFieldData item in _fields)
95 {
96 _fieldIndex.Add(item.Name, position);
97 position += 1;
98 }
99 }
100
101 #endregion
102#else
103 #region ISerializable
104
105 protected FieldDataList(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
106 {
107 _fields = (List<IFieldData>)(info.GetValue("Fields", typeof(List<IFieldData>)));
108 RebuildIndex();
109 }
110
111 public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
112 {
113 info.AddValue("Fields", _fields);
114 }
115
116 private void RebuildIndex()
117 {
118 var position = 0;
119 foreach (IFieldData item in _fields)
120 {
121 _fieldIndex.Add(item.Name, position);
122 position += 1;
123 }
124 }
125
126 #endregion
127#endif
128 }
129}
Inherit from this base class to easily create a serializable list class.
Interface defining callback methods used by the SerializationFormatterFactory.GetFormatter().
void Deserialized()
Method called on an object after deserialization is complete.
@ Serialization
The object is being serialized for a clone or data portal operation.
@ Serializable
Prevents updating or inserting until the transaction is complete.