0

There is one API method which looks like:

Task<Response> UpdateImage([AliasAs("banner_image")] StreamPart banner_image=null,[AliasAs("background_image")] StreamPart background_image =null);

But at a time only one image will be there from Frond-End

For ex. I got an image for banner_image then

APIHelper.UpdateImage(banner_image: image)

I getting the attribute information from one variable like,

string key = "banner_image";

So the question is how I can get the value of key and pass it like,

APIHelper.UpdateImage(`dynamic_key_extracted_from_key_variable_value`: image)

1 Answer 1

1

You cannot. That is a language/compiler feature, not available at runtime.

(And for a reason, how should it react when you suddenly pass "xzy"? Have a time-travelling compiler error that reaches you when you compiled it 2 weeks ago?)

Your easiest way around it might be:

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Have used switch case which manipulates the value on the basis of key but thinking is it possible or not with above approach

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.