コード例 #1
0
 /// <summary>
 /// 获取指定类型的所有属性元数据。
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public virtual List <SerializerPropertyMetadata> GetProperties(Type type)
 {
     return(_cache.GetOrAdd(type, k =>
     {
         return k.GetProperties()
         .Where(s => s.CanRead && !SerializerUtil.IsNoSerializable(_option, s))
         .Distinct(new SerializerUtil.PropertyEqualityComparer())
         .Select(s => new SerializerPropertyMetadata
         {
             Filter = (p, l) =>
             {
                 return !SerializerUtil.CheckLazyValueCreate(l, p.Name);
             },
             Getter = o => ReflectionCache.GetAccessor(s).GetValue(o),
             Setter = (o, v) => ReflectionCache.GetAccessor(s).SetValue(o, v),
             PropertyInfo = s,
             PropertyName = ResolvePropertyName(s),
             Formatter = s.GetCustomAttributes <TextFormatterAttribute>().FirstOrDefault()?.Formatter,
             DefaultValue = s.GetCustomAttributes <DefaultValueAttribute>().FirstOrDefault()?.Value,
             Converter = s.GetCustomAttributes <TextPropertyConverterAttribute>().FirstOrDefault()?.ConverterType.New <ITextConverter>()
         })
         .Where(s => !string.IsNullOrEmpty(s.PropertyName))
         .ToList();
     }));
 }
コード例 #2
0
ファイル: XmlSerialize.cs プロジェクト: wushian/fireasy2
 /// <summary>
 /// 获取指定类型的属性访问缓存。
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 private List <PropertyGetAccessorCache> GetAccessorCache(Type type)
 {
     return(context.GetAccessors.TryGetValue(type, () =>
     {
         return type.GetProperties()
         .Where(s => s.CanRead && !SerializerUtil.IsNoSerializable(option, s))
         .Distinct(new SerializerUtil.PropertyEqualityComparer())
         .Select(s => new PropertyGetAccessorCache
         {
             Accessor = ReflectionCache.GetAccessor(s),
             Filter = (p, l) =>
             {
                 return !SerializerUtil.CheckLazyValueCreate(l, p.Name);
             },
             PropertyInfo = s,
             PropertyName = SerializerUtil.GetPropertyName(s)
         })
         .Where(s => !string.IsNullOrEmpty(s.PropertyName))
         .ToList();
     }));
 }
コード例 #3
0
 /// <summary>
 /// 获取指定类型的属性访问缓存。
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public List <PropertyGetAccessorCache> GetAccessorCache(Type type)
 {
     return(GetAccessors.TryGetValue(type, () =>
     {
         return type.GetProperties()
         .Where(s => s.CanRead && !SerializerUtil.IsNoSerializable(Option, s))
         .Distinct(new SerializerUtil.PropertyEqualityComparer())
         .Select(s => new PropertyGetAccessorCache
         {
             Accessor = ReflectionCache.GetAccessor(s),
             Filter = (p, l) =>
             {
                 return !SerializerUtil.CheckLazyValueCreate(l, p.Name);
             },
             PropertyInfo = s,
             PropertyName = SerializerUtil.GetPropertyName(s),
             Formatter = s.GetCustomAttributes <TextFormatterAttribute>().FirstOrDefault()?.Formatter,
             DefaultValue = s.GetCustomAttributes <DefaultValueAttribute>().FirstOrDefault()?.Value,
             Converter = s.GetCustomAttributes <TextPropertyConverterAttribute>().FirstOrDefault()?.ConverterType.New <ITextConverter>()
         })
         .Where(s => !string.IsNullOrEmpty(s.PropertyName))
         .ToList();
     }));
 }