using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Xml.Linq;
using Neo.Afx.ComponentModel;
namespace Neo.Afx.Services.Integration
{
///
/// An instance of a .
///
[DataContract]
public class DataEntity
{
#region Constructor
///
/// Initializes a new instance of the class.
///
public DataEntity()
{
Properties = new Dictionary();
}
#endregion
#region Key
///
/// Gets or sets the key.
///
[Key]
[DataMember]
public string Key
{
get;
set;
}
#endregion
#region Title
///
/// Gets or sets the title.
///
[DataMember]
public string Title
{
get;
set;
}
#endregion
#region Properties
///
/// Gets the properties.
///
[DataMember]
public Dictionary Properties
{
get;
private set;
}
#endregion
#region Indexer
///
/// Gets or sets the with the specified property name.
///
public string this[string propertyName]
{
get
{
return Properties[propertyName];
}
set
{
Properties[propertyName] = value;
}
}
#endregion
#region Create
///
/// Creates a from the given XML representation.
///
/// The XML representation of the entity.
/// A instance.
public static DataEntity Create(XElement xml)
{
var result = new DataEntity
{
Key = xml.Element("key").ToString(string.Empty),
Title = xml.Element("title").ToString(string.Empty)
};
var properties = xml.Element("properties");
if(properties != null)
{
foreach(var property in properties.Elements())
{
result.Properties.Add(property.Name.LocalName, property.Value);
}
}
return result;
}
#endregion
}
}