123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Linq;
- using Ant.ORM;
- namespace Ant.Descriptors
- {
- public abstract class MemberDescriptor
- {
- Dictionary<Type, Attribute> _customAttributes = new Dictionary<Type, Attribute>();
- protected MemberDescriptor(FiledMetaData declaringEntityDescriptor)
- {
- this.DeclaringEntityDescriptor = declaringEntityDescriptor;
- }
- public FiledMetaData DeclaringEntityDescriptor { get; set; }
- /// <summary>
- /// 实体类每个成员
- /// </summary>
- public abstract MemberInfo MemberInfo { get; }
- public abstract Type MemberInfoType { get; }
- public abstract MemberTypes MemberType { get; }
- /// <summary>
- ///
- /// </summary>
- /// <param name="attributeType"></param>
- /// <returns></returns>
- 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);
- }
- }
- }
|