![](/img/trans.png)
[英]how to get the property value of IEnumerable and assign it to variable in C#?
[英]Get the value of variable and assign as attribute in C#
有一种API方法,如下所示:
Task<Response> UpdateImage([AliasAs("banner_image")] StreamPart banner_image=null,[AliasAs("background_image")] StreamPart background_image =null);
但一次只有Frond-End出现一张图像
对于前。 我得到了banner_image
的图像
APIHelper.UpdateImage(banner_image: image)
我从一个变量获取属性信息,例如
string key = "banner_image";
所以问题是我如何获得key
的值并像这样传递它,
APIHelper.UpdateImage(`dynamic_key_extracted_from_key_variable_value`: image)
你不能。 这是一种语言/编译器功能,在运行时不可用。
(由于某种原因,当您突然传递“ xzy”时它会如何反应?在2周前进行编译时会遇到遍历的编译器错误吗?)
最简单的解决方法可能是:
StreamPart banner_image = null;
StreamPart background_image = null;
if(key == "banner_image")
{
banner_image = value;
}
if(key == "background_image")
{
background_image = value;
}
UpdateImage(banner_image, background_image);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.