Esempio n. 1
0
        public HttpResponseMessage Get()
        {
            Address address = new Address
            {
                Province = "江苏省",
                City     = "苏州市",
                District = "工业园区",
                Street   = "星湖街328号"
            };
            Contact contact = new Contact
            {
                Name         = "张三",
                PhoneNo      = "123456789",
                EmailAddress = "*****@*****.**",
                Address      = address
            };
            IBodyModelValidator validator     = new DefaultBodyModelValidator();
            HttpActionContext   actionContext = new HttpActionContext
            {
                ControllerContext = this.ControllerContext
            };
            ModelMetadataProvider metadataProvider = actionContext.GetMetadataProvider();

            validator.Validate(contact, typeof(Contact), metadataProvider, actionContext, "contact");
            return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, actionContext.ModelState));
        }
        public bool Validate(object model, Type type, ModelMetadataProvider metadataProvider, HttpActionContext actionContext, string keyPrefix)
        {
            if (model is Entity)
            {
                return(true);
            }

            return(_inner.Validate(model, type, metadataProvider, actionContext, keyPrefix));
        }