using System; using System.Collections.Concurrent; using System.Reflection; namespace OS.Common.ComUtils { /// /// 内部使用获取属性相关信息 /// internal static class TypeUtil { private static ConcurrentDictionary attrDirs = new ConcurrentDictionary(); public static object[] GetPropertiAttributes( string typeName, PropertyInfo fd, Type attributeType ) { string key = string.Concat( typeName, fd.Name ); object[] attrs; attrDirs.TryGetValue( key, out attrs ); if (attrs != null) { return attrs; } attrs = fd.GetCustomAttributes( attributeType, true ); attrDirs.TryAdd( key, attrs ); return attrs; } private static ConcurrentDictionary proDictionaries = new ConcurrentDictionary(); public static PropertyInfo[] GetProperties( Type type ) { PropertyInfo[] properties; proDictionaries.TryGetValue( type.FullName, out properties ); if (properties != null) { return properties; } properties = type.GetProperties( BindingFlags.Public | BindingFlags.Instance ); proDictionaries.TryAdd( type.FullName, properties ); return properties; } } }