using System; using System.Collections.Generic; using System.Reflection; using System.Linq; using Ant.ORM; namespace Ant.Descriptors { public abstract class MemberDescriptor { Dictionary _customAttributes = new Dictionary(); protected MemberDescriptor(FiledMetaData declaringEntityDescriptor) { this.DeclaringEntityDescriptor = declaringEntityDescriptor; } public FiledMetaData DeclaringEntityDescriptor { get; set; } /// /// 实体类每个成员 /// public abstract MemberInfo MemberInfo { get; } public abstract Type MemberInfoType { get; } public abstract MemberTypes MemberType { get; } /// /// /// /// /// public virtual Attribute GetCustomAttribute(Type attributeType) { Attribute val; if (!this._customAttributes.TryGetValue(attributeType, out val)) { val = this.MemberInfo.GetCustomAttributes(attributeType, false).FirstOrDefault() as Attribute; lock (this._customAttributes) { this._customAttributes[attributeType] = val; } } return val; } public bool IsDefined(Type attributeType) { return this.MemberInfo.IsDefined(attributeType, false); } } }