Exemplo n.º 1
0
        private ParameterInformation CreateParameterInfo(
            Type parameterType,
            IEnumerable <Attribute> attributes,
            string parameterName,
            IBinderMetadata binderMetadata)
        {
            var metadataProtoType = CreateMetadataPrototype(attributes: attributes,
                                                            containerType: null,
                                                            modelType: parameterType,
                                                            propertyName: parameterName);

            if (binderMetadata != null)
            {
                metadataProtoType.BinderMetadata = binderMetadata;
            }

            var nameProvider = binderMetadata as IModelNameProvider;

            if (nameProvider != null && nameProvider.Name != null)
            {
                metadataProtoType.ModelName = nameProvider.Name;
            }

            return(new ParameterInformation
            {
                Prototype = metadataProtoType
            });
        }
Exemplo n.º 2
0
        private ModelMetadata GetMetadataForParameterCore(Func <object> modelAccessor,
                                                          string parameterName,
                                                          ParameterInfo parameter,
                                                          IBinderMetadata binderMetadata)
        {
            var parameterInfo =
                CreateParameterInfo(parameter.ParameterType,
                                    parameter.GetCustomAttributes(),
                                    parameterName,
                                    binderMetadata);

            return(CreateMetadataFromPrototype(parameterInfo.Prototype, modelAccessor));
        }
        private void UpdateParameterMetadata(ModelMetadata metadata, IBinderMetadata binderMetadata)
        {
            if (binderMetadata != null)
            {
                metadata.BinderMetadata = binderMetadata;
            }

            var nameProvider = binderMetadata as IModelNameProvider;

            if (nameProvider != null && nameProvider.Name != null)
            {
                metadata.BinderModelName = nameProvider.Name;
            }
        }
Exemplo n.º 4
0
        public ModelMetadata GetMetadataForParameter(
            Func <object> modelAccessor,
            [NotNull] MethodInfo methodInfo,
            [NotNull] string parameterName,
            IBinderMetadata binderMetadata)
        {
            var parameter = methodInfo.GetParameters().FirstOrDefault(
                param => StringComparer.Ordinal.Equals(param.Name, parameterName));

            if (parameter == null)
            {
                var message = Resources.FormatCommon_ParameterNotFound(parameterName);
                throw new ArgumentException(message, nameof(parameterName));
            }

            return(GetMetadataForParameterCore(modelAccessor, parameterName, parameter, binderMetadata));
        }