Esempio n. 1
0
        public override ParameterBuilder DefineMethodParameter(
            MethodBuilder methodBuilder,
            FluentActionDefinition actionDefinition,
            FluentActionUsingDefinition usingDefinition,
            int parameterIndex)
        {
            var parameterBuilder = base.DefineMethodParameter(methodBuilder, actionDefinition, usingDefinition, parameterIndex);

            var attributeType = typeof(FromRouteAttribute);
            var name          = ((FluentActionUsingRouteParameterDefinition)usingDefinition).Name;

            if (!actionDefinition.RouteTemplate.Contains($"{{{name}}}", StringComparison.CurrentCultureIgnoreCase))
            {
                throw new Exception($"Route parameter {name} does not exist in routeTemplate {actionDefinition.RouteTemplate}.");
            }

            var attributeBuilder = new CustomAttributeBuilder(
                attributeType.GetConstructor(new Type[0]),
                new Type[0],
                new[] { attributeType.GetProperty("Name") },
                new object[] { name });

            parameterBuilder.SetCustomAttribute(attributeBuilder);

            return(parameterBuilder);
        }
Esempio n. 2
0
        public override ParameterBuilder DefineMethodParameter(
            MethodBuilder methodBuilder,
            FluentActionDefinition actionDefinition,
            FluentActionUsingDefinition usingDefinition,
            int parameterIndex)
        {
            var parameterBuilder = base.DefineMethodParameter(methodBuilder, actionDefinition, usingDefinition, parameterIndex);

            var attributeType         = typeof(ModelBinderAttribute);
            var modelBinderDefinition = ((FluentActionUsingModelBinderDefinition)usingDefinition);
            var modelBinderType       = modelBinderDefinition.ModelBinderType;

            PropertyInfo[] propertyTypes  = null;
            object[]       propertyValues = null;
            if (!string.IsNullOrWhiteSpace(modelBinderDefinition.ParameterName))
            {
                propertyTypes = new[]
                {
                    attributeType.GetProperty("BinderType"),
                    attributeType.GetProperty("Name")
                };
                propertyValues = new object[]
                {
                    modelBinderType,
                    modelBinderDefinition.ParameterName
                };
            }
            else
            {
                propertyTypes = new[]
                {
                    attributeType.GetProperty("BinderType")
                };
                propertyValues = new object[]
                {
                    modelBinderType
                };
            }

            var attributeBuilder = new CustomAttributeBuilder(
                attributeType.GetConstructor(new Type[0]),
                new Type[0],
                propertyTypes,
                propertyValues);

            parameterBuilder.SetCustomAttribute(attributeBuilder);

            return(parameterBuilder);
        }
        public override ParameterBuilder DefineMethodParameter(
            MethodBuilder methodBuilder,
            FluentActionDefinition actionDefinition,
            FluentActionUsingDefinition usingDefinition,
            int parameterIndex)
        {
            var parameterBuilder = base.DefineMethodParameter(methodBuilder, actionDefinition, usingDefinition, parameterIndex);

            var attributeBuilder = new CustomAttributeBuilder(typeof(FromFormAttribute)
                                                              .GetConstructor(new Type[0]), new Type[0]);

            parameterBuilder.SetCustomAttribute(attributeBuilder);

            return(parameterBuilder);
        }
        public virtual ParameterBuilder DefineMethodParameter(MethodBuilder methodBuilder,
                                                              FluentActionDefinition actionDefinition,
                                                              FluentActionUsingDefinition usingDefinition,
                                                              int parameterIndex)
        {
            var parameterBuilder = methodBuilder.DefineParameter(
                parameterIndex,
                usingDefinition.HasDefaultValue ? ParameterAttributes.HasDefault : ParameterAttributes.None,
                usingDefinition.MethodParameterName ?? $"parameter{parameterIndex}");

            if (usingDefinition.HasDefaultValue)
            {
                parameterBuilder.SetConstant(usingDefinition.DefaultValue);
            }

            return(parameterBuilder);
        }
Esempio n. 5
0
        public override ParameterBuilder DefineMethodParameter(
            MethodBuilder methodBuilder,
            FluentActionDefinition actionDefinition,
            FluentActionUsingDefinition usingDefinition,
            int parameterIndex)
        {
            var parameterBuilder = base.DefineMethodParameter(methodBuilder, actionDefinition, usingDefinition, parameterIndex);

            var attributeType = typeof(FromFormAttribute);
            var key           = ((FluentActionUsingFormValueDefinition)usingDefinition).Key;

            var attributeBuilder = new CustomAttributeBuilder(
                attributeType.GetConstructor(new Type[0]),
                new Type[0],
                new[] { attributeType.GetProperty("Name") },
                new object[] { key });

            parameterBuilder.SetCustomAttribute(attributeBuilder);

            return(parameterBuilder);
        }
Esempio n. 6
0
 public FluentActionWithMvcController(FluentActionDefinition fluentActionDefinition, FluentActionUsingDefinition usingDefinition) : base(fluentActionDefinition)
 {
     Definition.ExistingOrNewHandlerDraft.Usings.Add(usingDefinition);
 }