Adding support for ActivateAttribute via IControllerActivator

This mechanism replaces code in Inject that activated properties
by looking them up by names.


How can a controller be a value type? 

-----Original Message-----
From: "Pranav K" <notifications@github.com>
Sent: ‎6/‎13/‎2014 11:44 AM
To: "aspnet/Mvc" <Mvc@noreply.github.com>
Cc: "Yishai Galatzer" <yishai_galatzer@yahoo.com>
Subject: Re: [Mvc] Adding support for ActivateAttribute viaIControllerActivator (#648)

In src/Microsoft.AspNet.Mvc.Core/DefaultControllerActivator.cs:
> +            private readonly PropertyInfo _propertyInfo;
> +            private readonly Func<ActionContext, object> _valueAccessor;
> +            private readonly Action<object, object> _fastPropertySetter;
> +
> +            public ActivateInfo(PropertyInfo propertyInfo,
> +                                Func<ActionContext, object> valueAccessor)
> +            {
> +                _propertyInfo = propertyInfo;
> +                _valueAccessor = valueAccessor;
> +
> +                // The fast property setter does not work with value types - casting it from object type to 
> +                // TDeclaringType creates a new value type and we end up setting the property value on this new
> +                // instance. We'll use the slow reflection code path to activate value types.
> +                if (!propertyInfo.DeclaringType.GetTypeInfo().IsValueType)
> +                {
> +                    _fastPropertySetter = PropertyHelper.MakeFastPropertySetter(propertyInfo);
This is about the controller being a value type and not the property itself. In this case, we use reflection

We do set value types but using the slow reflection code path.
—
Reply to this email directly or view it on GitHub.