MemberDescriptor.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.Linq;
  5. using Ant.ORM;
  6. namespace Ant.Descriptors
  7. {
  8. public abstract class MemberDescriptor
  9. {
  10. Dictionary<Type, Attribute> _customAttributes = new Dictionary<Type, Attribute>();
  11. protected MemberDescriptor(FiledMetaData declaringEntityDescriptor)
  12. {
  13. this.DeclaringEntityDescriptor = declaringEntityDescriptor;
  14. }
  15. public FiledMetaData DeclaringEntityDescriptor { get; set; }
  16. /// <summary>
  17. /// 实体类每个成员
  18. /// </summary>
  19. public abstract MemberInfo MemberInfo { get; }
  20. public abstract Type MemberInfoType { get; }
  21. public abstract MemberTypes MemberType { get; }
  22. /// <summary>
  23. ///
  24. /// </summary>
  25. /// <param name="attributeType"></param>
  26. /// <returns></returns>
  27. public virtual Attribute GetCustomAttribute(Type attributeType)
  28. {
  29. Attribute val;
  30. if (!this._customAttributes.TryGetValue(attributeType, out val))
  31. {
  32. val = this.MemberInfo.GetCustomAttributes(attributeType, false).FirstOrDefault() as Attribute;
  33. lock (this._customAttributes)
  34. {
  35. this._customAttributes[attributeType] = val;
  36. }
  37. }
  38. return val;
  39. }
  40. public bool IsDefined(Type attributeType)
  41. {
  42. return this.MemberInfo.IsDefined(attributeType, false);
  43. }
  44. }
  45. }