author | StephaneLenclud |
Thu, 18 Aug 2016 17:13:21 +0200 | |
changeset 239 | dd7770b97916 |
parent 238 | c92587ddabcd |
child 243 | cc2251d065db |
permissions | -rw-r--r-- |
StephaneLenclud@238 | 1 |
using System; |
StephaneLenclud@238 | 2 |
using System.Collections.Generic; |
StephaneLenclud@238 | 3 |
using System.Linq; |
StephaneLenclud@238 | 4 |
using System.Text; |
StephaneLenclud@238 | 5 |
using System.Threading.Tasks; |
StephaneLenclud@238 | 6 |
|
StephaneLenclud@238 | 7 |
|
StephaneLenclud@238 | 8 |
using System; |
StephaneLenclud@238 | 9 |
using System.Collections.Generic; |
StephaneLenclud@238 | 10 |
using System.Runtime.Serialization; |
StephaneLenclud@238 | 11 |
|
StephaneLenclud@238 | 12 |
|
StephaneLenclud@238 | 13 |
namespace SharpLib.Ear |
StephaneLenclud@238 | 14 |
{ |
StephaneLenclud@238 | 15 |
|
StephaneLenclud@238 | 16 |
/// <summary> |
StephaneLenclud@238 | 17 |
/// EAR object provides serialization support. |
StephaneLenclud@238 | 18 |
/// It assumes most derived class is decorated with AttributeObject. |
StephaneLenclud@238 | 19 |
/// </summary> |
StephaneLenclud@238 | 20 |
[DataContract] |
StephaneLenclud@238 | 21 |
[KnownType("DerivedTypes")] |
StephaneLenclud@238 | 22 |
public abstract class Object: IComparable |
StephaneLenclud@238 | 23 |
{ |
StephaneLenclud@239 | 24 |
/// <summary> |
StephaneLenclud@239 | 25 |
/// Static object name. |
StephaneLenclud@239 | 26 |
/// </summary> |
StephaneLenclud@238 | 27 |
public string Name |
StephaneLenclud@238 | 28 |
{ |
StephaneLenclud@238 | 29 |
//Get the name of this object attribute |
StephaneLenclud@238 | 30 |
get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name; } |
StephaneLenclud@238 | 31 |
private set { } |
StephaneLenclud@238 | 32 |
} |
StephaneLenclud@238 | 33 |
|
StephaneLenclud@239 | 34 |
/// <summary> |
StephaneLenclud@239 | 35 |
/// Static object description. |
StephaneLenclud@239 | 36 |
/// </summary> |
StephaneLenclud@238 | 37 |
public string Description |
StephaneLenclud@238 | 38 |
{ |
StephaneLenclud@238 | 39 |
//Get the description of this object attribute |
StephaneLenclud@238 | 40 |
get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Description; } |
StephaneLenclud@238 | 41 |
private set { } |
StephaneLenclud@238 | 42 |
} |
StephaneLenclud@238 | 43 |
|
StephaneLenclud@239 | 44 |
/// <summary> |
StephaneLenclud@239 | 45 |
/// Dynamic object description. |
StephaneLenclud@239 | 46 |
/// </summary> |
StephaneLenclud@239 | 47 |
/// <returns></returns> |
StephaneLenclud@238 | 48 |
public virtual string Brief() |
StephaneLenclud@238 | 49 |
{ |
StephaneLenclud@238 | 50 |
return Name; |
StephaneLenclud@238 | 51 |
} |
StephaneLenclud@238 | 52 |
|
StephaneLenclud@239 | 53 |
/// <summary> |
StephaneLenclud@239 | 54 |
/// Needed to make sure our sorting makes sense |
StephaneLenclud@239 | 55 |
/// </summary> |
StephaneLenclud@239 | 56 |
/// <param name="obj"></param> |
StephaneLenclud@239 | 57 |
/// <returns></returns> |
StephaneLenclud@238 | 58 |
public int CompareTo(object obj) |
StephaneLenclud@238 | 59 |
{ |
StephaneLenclud@238 | 60 |
//Sort by object name |
StephaneLenclud@238 | 61 |
return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name.CompareTo(obj.GetType()); |
StephaneLenclud@238 | 62 |
} |
StephaneLenclud@238 | 63 |
|
StephaneLenclud@238 | 64 |
/// <summary> |
StephaneLenclud@239 | 65 |
/// Tells whether the current object configuration is valid. |
StephaneLenclud@239 | 66 |
/// </summary> |
StephaneLenclud@239 | 67 |
/// <returns></returns> |
StephaneLenclud@239 | 68 |
public virtual bool IsValid() |
StephaneLenclud@239 | 69 |
{ |
StephaneLenclud@239 | 70 |
return true; |
StephaneLenclud@239 | 71 |
} |
StephaneLenclud@239 | 72 |
|
StephaneLenclud@239 | 73 |
/// <summary> |
StephaneLenclud@238 | 74 |
/// So that data contract knows all our types. |
StephaneLenclud@238 | 75 |
/// </summary> |
StephaneLenclud@238 | 76 |
/// <returns></returns> |
StephaneLenclud@238 | 77 |
private static IEnumerable<Type> DerivedTypes() |
StephaneLenclud@238 | 78 |
{ |
StephaneLenclud@238 | 79 |
return SharpLib.Utils.Reflection.GetDerivedTypes<Object>(); |
StephaneLenclud@238 | 80 |
} |
StephaneLenclud@238 | 81 |
|
StephaneLenclud@238 | 82 |
} |
StephaneLenclud@238 | 83 |
} |