using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Collections;
namespace SuperSocket.SocketBase
{
///
/// Status information collection
///
[Serializable]
public class StatusInfoCollection
{
[NonSerialized]
private Dictionary m_Values = new Dictionary();
///
/// Gets the values.
///
///
/// The values.
///
public Dictionary Values
{
get { return m_Values; }
}
///
/// Gets or sets the name.
///
///
/// The name.
///
public string Name { get; set; }
///
/// Gets or sets the tag.
///
///
/// The tag.
///
public string Tag { get; set; }
///
/// Gets or sets the collected time.
///
///
/// The collected time.
///
public DateTime CollectedTime { get; set; }
///
/// Gets or sets the with the specified name.
///
///
/// The .
///
/// The name.
///
public object this[string name]
{
get
{
object value;
if (m_Values.TryGetValue(name, out value))
return value;
return null;
}
set
{
m_Values[name] = value;
}
}
///
/// Gets the value.
///
///
/// The name.
/// The default value.
///
public T GetValue(string name, T defaultValue)
where T : struct
{
object value;
if (m_Values.TryGetValue(name, out value))
return (T)value;
return defaultValue;
}
private List> m_InternalList;
[OnSerializing]
private void OnSerializing(StreamingContext context)
{
m_InternalList = new List>(m_Values.Count);
foreach (var entry in m_Values)
{
m_InternalList.Add(new KeyValuePair(entry.Key, entry.Value));
}
}
[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
if (m_InternalList == null || m_InternalList.Count <= 0)
return;
if (m_Values == null)
m_Values = new Dictionary();
foreach (var entry in m_InternalList)
{
m_Values.Add(entry.Key, entry.Value);
}
m_InternalList = null;
}
}
}