protected virtual void InspectProperties(ComponentModel model)
        {
            var targetType = model.Implementation;

#if SILVERLIGHT
            if (targetType.IsVisible == false)
            {
                return;
            }
#endif
            if (model.InspectionBehavior == PropertiesInspectionBehavior.Undefined)
            {
                model.InspectionBehavior = GetInspectionBehaviorFromTheConfiguration(model.Configuration);
            }

            if (model.InspectionBehavior == PropertiesInspectionBehavior.None)
            {
                // Nothing to be inspected
                return;
            }

            var properties = GetProperties(model, targetType);
            if (properties.Count == 0)
            {
                return;
            }
            var filters = StandardPropertyFilters.GetPropertyFilters(model, false);
            if (filters == null)
            {
                properties.ForEach(p => model.AddProperty(BuildDependency(p, isOptional: true)));
            }
            else
            {
                foreach (var filter in filters.Concat(new[] { StandardPropertyFilters.Create(PropertyFilter.Default) }))
                {
                    var dependencies = filter.Invoke(model, properties, BuildDependency);
                    if (dependencies != null)
                    {
                        foreach (var dependency in dependencies)
                        {
                            model.AddProperty(dependency);
                        }
                    }
                    if (properties.Count == 0)
                    {
                        return;
                    }
                }
            }
        }
        protected virtual void InspectProperties(ComponentModel model)
        {
            var targetType = model.Implementation;

#if SILVERLIGHT
            if (targetType.IsVisible == false)
            {
                return;
            }
#endif
            if (model.InspectionBehavior == PropertiesInspectionBehavior.Undefined)
            {
                model.InspectionBehavior = GetInspectionBehaviorFromTheConfiguration(model.Configuration);
            }

            if (model.InspectionBehavior == PropertiesInspectionBehavior.None)
            {
                // Nothing to be inspected
                return;
            }

            BindingFlags bindingFlags;
            if (model.InspectionBehavior == PropertiesInspectionBehavior.DeclaredOnly)
            {
                bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
            }
            else             // if (model.InspectionBehavior == PropertiesInspectionBehavior.All) or Undefined
            {
                bindingFlags = BindingFlags.Public | BindingFlags.Instance;
            }

            var properties = targetType.GetProperties(bindingFlags);
            var filters    = GetPropertyFilters(model);
            foreach (var property in properties)
            {
                if (!property.CanWrite || property.GetSetMethod() == null)
                {
                    continue;
                }

                var indexerParams = property.GetIndexParameters();

                if (indexerParams != null && indexerParams.Length != 0)
                {
                    continue;
                }

                if (property.IsDefined(typeof(DoNotWireAttribute), true))
                {
                    continue;
                }
                if (filters != null && filters.Any(f => f(property) == false))
                {
                    continue;
                }
                var dependency = new DependencyModel(property.Name, property.PropertyType, isOptional: true);
                model.AddProperty(new PropertySet(property, dependency));
            }
        }
 void AddFilteredPropertyDependenciesToModel(ComponentModel model, ICollection <PropertyDependencyFilter> filters,
                                             PropertyInfo[] properties)
 {
     foreach (var dependencies in
              filters.Select(filter => filter.Invoke(model, properties, BuildDependency))
              .Where(dependencies => dependencies != null))
     {
         foreach (var dependency in dependencies)
         {
             model.AddProperty(dependency);
         }
     }
 }
Пример #4
0
        public void ProcessModel(IKernel kernel, ComponentModel model)
        {
            var targetType = model.Implementation;

            // we only inject properties on ViewModels
            if (!(targetType.Name.EndsWith("ViewModel") && targetType.IsBasedOn(typeof(ViewModelBase))))
            {
                return;
            }

            var properties = GetProperties(model, targetType)
                             .Where(property => property.CanWrite &&
                                    property.GetSetMethod() != null &&
                                    property.PropertyType.IsBasedOn(typeof(CommandBase)) &&
                                    !property.PropertyType.IsAbstract);

            foreach (var property in properties)
            {
                model.AddProperty(BuildDependency(property));
            }
        }
 void AddAllPropertyDependenciesToModel(ComponentModel model, PropertyInfo[] properties)
 {
     properties.ForEach(p => model.AddProperty(BuildDependency(p, true)));
 }