InheritanceAttribute.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // System.ComponentModel.InheritanceAttribute
  3. //
  4. // Authors:
  5. // Martin Willemoes Hansen ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) 2003 Martin Willemoes Hansen
  9. // (C) 2003 Andreas Nahr
  10. //
  11. namespace System.ComponentModel
  12. {
  13. [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event)]
  14. public sealed class InheritanceAttribute : Attribute
  15. {
  16. private InheritanceLevel level;
  17. public static readonly InheritanceAttribute Default = new InheritanceAttribute ();
  18. public static readonly InheritanceAttribute Inherited = new InheritanceAttribute (InheritanceLevel.Inherited);
  19. public static readonly InheritanceAttribute InheritedReadOnly = new InheritanceAttribute (InheritanceLevel.InheritedReadOnly);
  20. public static readonly InheritanceAttribute NotInherited = new InheritanceAttribute (InheritanceLevel.NotInherited);
  21. public InheritanceAttribute()
  22. {
  23. this.level = InheritanceLevel.NotInherited;
  24. }
  25. public InheritanceAttribute (InheritanceLevel inheritanceLevel)
  26. {
  27. this.level = inheritanceLevel;
  28. }
  29. public InheritanceLevel InheritanceLevel {
  30. get { return level; }
  31. }
  32. public override bool Equals (object obj)
  33. {
  34. if (!(obj is InheritanceAttribute))
  35. return false;
  36. if (obj == this)
  37. return true;
  38. return ((InheritanceAttribute) obj).InheritanceLevel == level;
  39. }
  40. public override int GetHashCode()
  41. {
  42. return level.GetHashCode ();
  43. }
  44. public override bool IsDefaultAttribute()
  45. {
  46. return level == InheritanceAttribute.Default.InheritanceLevel;
  47. }
  48. public override string ToString()
  49. {
  50. return this.level.ToString ();
  51. }
  52. }
  53. }