public AddGetters ( IEnumerable |
||
gets | IEnumerable |
The getters. |
return | PropertyDescriptor |
private static Dictionary <String, PropertyDescriptor> GetPropertyDescriptors( Type type, out IDictionaryInitializer[] typeInitializers, out IDictionaryMetaInitializer[] metaInitializers, out object[] typeBehaviors) { var propertyMap = new Dictionary <String, PropertyDescriptor>(); var interfaceBehaviors = typeBehaviors = ExpandBehaviors(GetInterfaceBehaviors <object>(type)).ToArray(); typeInitializers = typeBehaviors.OfType <IDictionaryInitializer>().Prioritize().ToArray(); metaInitializers = typeBehaviors.OfType <IDictionaryMetaInitializer>().Prioritize().ToArray(); var defaultFetch = typeBehaviors.OfType <FetchAttribute>().Select(b => b.Fetch).FirstOrDefault(); CollectProperties(type, property => { var propertyBehaviors = ExpandBehaviors(GetPropertyBehaviors <object>(property)).ToArray(); var propertyDescriptor = new PropertyDescriptor(property, propertyBehaviors); var descriptorInitializers = propertyBehaviors.OfType <IPropertyDescriptorInitializer>(); foreach (var descriptorInitializer in descriptorInitializers.OrderBy(b => b.ExecutionOrder)) { descriptorInitializer.Initialize(propertyDescriptor, propertyBehaviors); } propertyDescriptor.AddKeyBuilders( propertyBehaviors.OfType <IDictionaryKeyBuilder>().Prioritize( GetInterfaceBehaviors <IDictionaryKeyBuilder>(property.ReflectedType)) ); propertyDescriptor.AddGetters( propertyBehaviors.OfType <IDictionaryPropertyGetter>().Prioritize( interfaceBehaviors.OfType <IDictionaryPropertyGetter>()) ); AddDefaultGetter(propertyDescriptor); propertyDescriptor.AddSetters( propertyBehaviors.OfType <IDictionaryPropertySetter>().Prioritize( interfaceBehaviors.OfType <IDictionaryPropertySetter>()) ); bool?propertyFetch = (from b in propertyBehaviors.OfType <FetchAttribute>() select b.Fetch).FirstOrDefault(); propertyDescriptor.Fetch = propertyFetch.GetValueOrDefault(defaultFetch); PropertyDescriptor existingDescriptor; if (propertyMap.TryGetValue(property.Name, out existingDescriptor)) { var existingProperty = existingDescriptor.Property; if (existingProperty.PropertyType == property.PropertyType) { if (property.CanRead && property.CanWrite) { propertyMap[property.Name] = propertyDescriptor; } return; } } propertyMap.Add(property.Name, propertyDescriptor); }); return(propertyMap); }
/// <summary> /// Copies the property getters to the other <see cref="PropertyDescriptor"/> /// </summary> /// <param name="other"></param> /// <returns></returns> public PropertyDescriptor CopyGetters(PropertyDescriptor other) { if (getters != null) { other.AddGetters(getters); } return(this); }
/// <summary> /// Copies the property getters to the other <see cref="PropertyDescriptor"/> /// </summary> /// <param name="other"></param> /// <returns></returns> public PropertyDescriptor CopyGetters(PropertyDescriptor other) { if (getters != null) { other.AddGetters(getters.Select(getter => getter.Copy()).OfType <IDictionaryPropertyGetter>()); } return(this); }
/// <summary> /// Copies the selected property getters to the other <see cref="PropertyDescriptor"/> /// </summary> /// <param name="other"></param> /// <param name="selector"></param> /// <returns></returns> public PropertyDescriptor CopyGetters(PropertyDescriptor other, Func <IDictionaryPropertyGetter, bool> selector) { if (selector == null) { throw new ArgumentNullException("selector"); } if (getters != null) { other.AddGetters(getters.Where(selector)); } return(this); }
/// <summary> /// Copies the selected property getters to the other <see cref="PropertyDescriptor"/> /// </summary> /// <param name="other"></param> /// <param name="selector"></param> /// <returns></returns> public PropertyDescriptor CopyGetters(PropertyDescriptor other, Func<IDictionaryPropertyGetter, bool> selector) { if (selector == null) { throw new ArgumentNullException("selector"); } if (getters != null) { other.AddGetters(getters.Where(selector)); } return this; }
/// <summary> /// Copies the property getters to the other <see cref="PropertyDescriptor"/> /// </summary> /// <param name="other"></param> /// <returns></returns> public PropertyDescriptor CopyGetters(PropertyDescriptor other) { if (getters != null) { other.AddGetters(getters); } return this; }
/// <summary> /// Copies the property getters to the other <see cref="PropertyDescriptor"/> /// </summary> /// <param name="other"></param> /// <returns></returns> public PropertyDescriptor CopyGetters(PropertyDescriptor other) { if (getters != null) { other.AddGetters(getters.Select(getter => getter.Copy()).OfType<IDictionaryPropertyGetter>()); } return this; }