/// <summary>
/// Descriptor information.
/// </summary>
public class Descriptor<K> {
/// <summary>
/// Key.
/// </summary>
public K Key { get; set; }
/// <summary>
/// Name.
/// </summary>
public String Name { get; set; }
/// <summary>
/// Description
/// </summary>
public String Description { get; set; }
/// <summary>
/// Get descriptor caption.
/// </summary>
public String Caption {
get {
if (String.IsNullOrEmpty(Description))
return Name;
return String.Format("{0} - {1}", Name, Description);
}
}
/// <summary>
/// To String
/// </summary>
/// <returns>Default string display on binding list</returns>
public override string ToString() {
return Caption;
}
/// <summary>
/// Equals
/// </summary>
/// <param name="obj">Equals object</param>
/// <returns>When object has same key return true else return false</returns>
public override bool Equals(object obj) {
if (obj is Descriptor<K>) {
return ((Descriptor<K>)obj).Key.Equals(Key);
}
return base.Equals(obj);
}
/// <summary>
/// Get hashcode.
/// </summary>
/// <returns>Hashcode</returns>
public override int GetHashCode() {
return Key.GetHashCode();
}
}
/// <summary>
/// Get all resource descriptors.
/// </summary>
/// <returns>Resource descriptor list</returns>
public static async Task<IList<Descriptor<Int32>>> GetAllDescriptors() {
using (MesproContext db = GetContext()) {
return await db.Resources
.OrderBy(m => m.Name)
.Select(m => new Descriptor<Int32>() { Key = m.ID, Name = m.Name, Description = m.Description })
.ToListAsync();
}
}