AddKeyBuilders() public method

Adds the key builders.
public AddKeyBuilders ( IEnumerable builders ) : PropertyDescriptor
builders IEnumerable The builders.
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 key builders to the other <see cref="PropertyDescriptor"/>
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public PropertyDescriptor CopyKeyBuilders(PropertyDescriptor other)
 {
     if (keyBuilders != null)
     {
         other.AddKeyBuilders(keyBuilders);
     }
     return(this);
 }
Example #3
0
 /// <summary>
 /// Copies the key builders to the other <see cref="PropertyDescriptor"/>
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public PropertyDescriptor CopyKeyBuilders(PropertyDescriptor other)
 {
     if (keyBuilders != null)
     {
         other.AddKeyBuilders(keyBuilders.Select(builder => builder.Copy()).OfType <IDictionaryKeyBuilder>());
     }
     return(this);
 }
 /// <summary>
 /// Copies the selected key builders to the other <see cref="PropertyDescriptor"/>
 /// </summary>
 /// <param name="other"></param>
 /// <param name="selector"></param>
 /// <returns></returns>
 public PropertyDescriptor CopyKeyBuilders(PropertyDescriptor other, Func <IDictionaryKeyBuilder, bool> selector)
 {
     if (selector == null)
     {
         throw new ArgumentNullException("selector");
     }
     if (keyBuilders != null)
     {
         other.AddKeyBuilders(keyBuilders.Where(selector));
     }
     return(this);
 }
		/// <summary>
		/// Copies the selected key builders to the other <see cref="PropertyDescriptor"/>
		/// </summary>
		/// <param name="other"></param>
		/// <param name="selector"></param>
		/// <returns></returns>
		public PropertyDescriptor CopyKeyBuilders(PropertyDescriptor other, Func<IDictionaryKeyBuilder, bool> selector)
		{
			if (selector == null)
			{
				throw new ArgumentNullException("selector");
			}
			if (keyBuilders != null)
			{
				other.AddKeyBuilders(keyBuilders.Where(selector));
			}
			return this;
		}
		/// <summary>
		/// Copies the key builders to the other <see cref="PropertyDescriptor"/>
		/// </summary>
		/// <param name="other"></param>
		/// <returns></returns>
		public PropertyDescriptor CopyKeyBuilders(PropertyDescriptor other)
		{
			if (keyBuilders != null)
			{
				other.AddKeyBuilders(keyBuilders);
			}
			return this;
		}
		/// <summary>
		/// Copies the key builders to the other <see cref="PropertyDescriptor"/>
		/// </summary>
		/// <param name="other"></param>
		/// <returns></returns>
		public PropertyDescriptor CopyKeyBuilders(PropertyDescriptor other)
		{
			if (keyBuilders != null)
			{
				other.AddKeyBuilders(keyBuilders.Select(builder => builder.Copy()).OfType<IDictionaryKeyBuilder>());
			}
			return this;
		}