web api:将数据添加到HttpResponseMessage(web api: add data to the HttpResponseMessage)
我在我的web api中有一个动作,它返回一个
HttpResponseMessage
:public async Task<HttpResponseMessage> Create([FromBody] AType payload) { if (payload == null) { throw new ArgumentNullException(nameof(payload)); } await Task.Delay(1); var t = new T { Id = 0, Name = payload.tName, Guid = Guid.NewGuid() }; var response = new MyResponse { T = t }; var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent(typeof(MyResponse), response, new JsonMediaTypeFormatter { SerializerSettings = { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore } }) }; return result; }
现在,我的问题是,如果发出请求并且请求的
Content-Type
是application/xml
,我应该使用xml formatter
放置响应的主体。有没有办法使用泛型类,让框架根据请求的内容类型决定在运行时使用哪种格式化程序?
I have an action in my web api that is returning a
HttpResponseMessage
:public async Task<HttpResponseMessage> Create([FromBody] AType payload) { if (payload == null) { throw new ArgumentNullException(nameof(payload)); } await Task.Delay(1); var t = new T { Id = 0, Name = payload.tName, Guid = Guid.NewGuid() }; var response = new MyResponse { T = t }; var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent(typeof(MyResponse), response, new JsonMediaTypeFormatter { SerializerSettings = { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore } }) }; return result; }
Now, my problem is that if a request is made and the request's
Content-Type
isapplication/xml
, I should put the response's body using axml formatter
.Is there a way to use a generic class and let the framework decide what formatter to use at runtime based on the request's content type?
原文:https://stackoverflow.com/questions/40677906
最满意答案
在AS3中,您可以使用显示对象的
scaleX
和scaleY属性来保持原始宽高比。以下是按比例缩放项目的常用方法:
floorplanImg.height = 890; //when you change the height, it automatically changes the scaleY to the relative amount from the original (1) floorplanImg.scaleX = floorplanImg.scaleY; //make the scaleX the same as the new scaleY to keep the aspect ratio the same
相对而言,缩放属性基本上只是宽度/高度的替代 -
1
是原生大小,2
是大小的两倍,0.5
是一半等...In AS3 you can use a display object's
scaleX
& scaleY properties to maintain the native aspect ratio.Here is a common way to proportionally scale an item:
floorplanImg.height = 890; //when you change the height, it automatically changes the scaleY to the relative amount from the original (1) floorplanImg.scaleX = floorplanImg.scaleY; //make the scaleX the same as the new scaleY to keep the aspect ratio the same
The scale properties are essentially just alternative to width/height in relative terms -
1
being native size,2
being double the size,0.5
being half etc...
相关问答
更多-
你是否处于这个问题? 或者只是好奇他们为什么是-1? 无论哪种方式它不是调试器的问题,属性实际上是-1。 这只是推测,但是直到使用/绘制位图之前,宽度和高度可以是-1,因为它并不重要,并且很可能是实现中的优化。 Are you in a situation where this is an issue? Or merely curious why they are -1? Either way it is not a debugger issue, the properties are actually - ...
-
使用-resize 100x将图像的大小调整为100像素宽,同时保持高度的宽高比。 阅读精细的ImageMagick手册了解详情。 Use -resize 100x to resize images to 100 pixels in width while maintaining the height's aspect ratio. Read the fine ImageMagick manual for details.
-
ActionScript 3阶段宽度(ActionScript 3 stage width)[2023-03-21]
你的问题很可能是这一行: if(kugla1.y<=kugla1.height/2 || kugla1.height>=stage.stageHeight-kugla1.height/2) 在第二部分(在|| ),您将比较kugla1的高度而不是y位置。 您可能遇到的另一个问题是,您的球可能会遇到超过一帧的相同条件,因此最好将您的速度与当前的运动方向分开。 查看代码注释: 在第一帧中,您还需要两个额外的变量: var speedX:int=5; var speedY:int=5; var curSp ... -
在AS3中,您可以使用显示对象的scaleX和scaleY属性来保持原始宽高比。 以下是按比例缩放项目的常用方法: floorplanImg.height = 890; //when you change the height, it automatically changes the scaleY to the relative amount from the original (1) floorplanImg.scaleX = floorplanImg.scaleY; //make the scaleX ...
-
WPF中的比例最小宽度(Proportional min width in WPF)[2023-09-29]
因为没有意义 宽度=“126 *”MinWidth =“126 *” 与...一样 宽度= “126 *” 宽度=“126 *”MinWidth =“125 *” 与...一样 宽度= “126 *” 宽度=“126 *”MinWidth =“127 *” 与Width =“127 *”相同 Because it makes no sense Width="126*" MinWidth="126*" same as Width="126*" Width="126*" MinWidth="125*" same ... -
如何在android中根据设备dpi设置与宽度成正比的高度(How to set height proportional to width according to device dpi in android)[2021-11-16]
你可以像这样动态设置你的高度。 Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); ll.getLayoutParams().height = width/2; ll.getLayoutParams().width = width; ll.requestLayout(); You can set your height dynamically like this. Displ ... -
首先使用code.google.com/p/swfobject而不是embed标签,是的,你可以直接更改像this.width = width_from_js; 但是我记得swfo ... -
如果你真的能够在控制台上打印宽度和高度的值,那么你会更好地理解你的程序是否真的能够获取一些实际值。 当没有值尚未分配给它们时,您可能会调用宽度和高度。 检查此SO线程以获取更多信息。 I think it would help if you to actually print the values of width and height on the console so you would better understand if your program was really able to fetch ...
-
您应该首先尝试预加载图像: var img = new Image() img.onload = function() { // gets called when the img is loaded }; img.src = 'img.png'; 请记住,加载图像时会调用onload函数,因此它是异步的。 You should try to preload the image first: var img = new Image() img. ...
-
最有可能发生的事情如下: 您在platformLine中绘制一条线,从坐标(100,100)开始,到(110,100)结束,厚度为5px。 platformLine.width和platform.height分别为10和5。 当您创建大小为10,5的BitmapData并绘制platformLine时,默认情况下platformLine的origo将在BitmapData中的像素0,0处绘制。 由于该行从(100,100)开始,您绘制platformLine的空白部分,因此不会绘制任何内容。 要解决此问题, ...