AddSetters() public method

Adds the dictionary setters.
public AddSetters ( IEnumerable sets ) : PropertyDescriptor
sets IEnumerable The setters.
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 setters to the other <see cref="PropertyDescriptor"/>
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public PropertyDescriptor CopySetters(PropertyDescriptor other)
 {
     if (setters != null)
     {
         other.AddSetters(setters);
     }
     return(this);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Copies the property setters to the other <see cref="PropertyDescriptor"/>
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public PropertyDescriptor CopySetters(PropertyDescriptor other)
 {
     if (setters != null)
     {
         other.AddSetters(setters.Select(setter => setter.Copy()).OfType <IDictionaryPropertySetter>());
     }
     return(this);
 }
 /// <summary>
 /// Copies the selected property setters to the other <see cref="PropertyDescriptor"/>
 /// </summary>
 /// <param name="other"></param>
 /// <param name="selector"></param>
 /// <returns></returns>
 public PropertyDescriptor CopySetters(PropertyDescriptor other, Func <IDictionaryPropertySetter, bool> selector)
 {
     if (selector == null)
     {
         throw new ArgumentNullException("selector");
     }
     if (setters != null)
     {
         other.AddSetters(setters.Where(selector));
     }
     return(this);
 }
Ejemplo n.º 5
0
		/// <summary>
		/// Copies the selected property setters to the other <see cref="PropertyDescriptor"/>
		/// </summary>
		/// <param name="other"></param>
		/// <param name="selector"></param>
		/// <returns></returns>
		public PropertyDescriptor CopySetters(PropertyDescriptor other, Func<IDictionaryPropertySetter, bool> selector)
		{
			if (selector == null)
			{
				throw new ArgumentNullException("selector");
			}
			if (setters != null)
			{
				other.AddSetters(setters.Where(selector));
			}
			return this;
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Copies the property setters to the other <see cref="PropertyDescriptor"/>
		/// </summary>
		/// <param name="other"></param>
		/// <returns></returns>
		public PropertyDescriptor CopySetters(PropertyDescriptor other)
		{
			if (setters != null)
			{
				other.AddSetters(setters);
			}
			return this;
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Copies the property setters to the other <see cref="PropertyDescriptor"/>
		/// </summary>
		/// <param name="other"></param>
		/// <returns></returns>
		public PropertyDescriptor CopySetters(PropertyDescriptor other)
		{
			if (setters != null)
			{
				other.AddSetters(setters.Select(setter => setter.Copy()).OfType<IDictionaryPropertySetter>());
			}
			return this;
		}