1234567891011121314151617181920212223242526272829303132333435 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Reflection;
- using Bowin.Common.Utility;
- namespace Bowin.Common
- {
- [AttributeUsage( AttributeTargets.Property, AllowMultiple = false)]
- public class DataPropertyAttribute: Attribute
- {
- private static Dictionary<Type, PropertyInfo[]> dataProperties = new Dictionary<Type, PropertyInfo[]>();
- public static PropertyInfo[] GetDataProperties(Type entityType)
- {
- Guard.ArgumentNotNullOrEmpty(entityType, "entityType");
- if (dataProperties.ContainsKey(entityType))
- {
- return dataProperties[entityType];
- }
- lock (typeof(DataPropertyAttribute))
- {
- if (dataProperties.ContainsKey(entityType))
- {
- return dataProperties[entityType];
- }
- var properties = (from property in entityType.GetProperties()
- where property.GetCustomAttributes(typeof(DataPropertyAttribute), true).Any()
- select property).ToArray();
- dataProperties[entityType] = properties;
- return properties;
- }
- }
- }
- }
|