1

Im making a REST Client for a TradeHouse API, it has a giant object with multiple attributes and i want to Convert it into a Class for me to use. For now as i dont want to make my own deserializer im casting it in a "dynamic" and then taking the attributes i want out of it.

foreach (dynamic stash in xdDynObj.stashes)
            {
                int incrementer = 0;
                xStashes.dicStashes.Add(incrementer, new Stash());
                Stash workStash = xStashes.dicStashes[incrementer];
                workStash.stashAccountName = stash.accountName;
                workStash.stashLastCharacterName = stash.lastCharacterName;
                workStash.stashID = stash.id;
                workStash.stashType = stash.stashType;
                workStash.stashLeague = stash.league;
                incrementer = incrementer + 1;
            }

this for now works as fine as it should. Now there is a problem. The Object im trying to Convert has a Properity called "public" and i definetly need that. but as im trying to get it.

workStash.isStashPublic = stash.public;

it doesnt work as public is obviously a keyword in C#. is there any way to say : Ok please dont take keywords here. or smth like that?

thanks for every help.

  • 1
    C# has a syntax for this, you use a `@` prefix: `workStash.isStashPublic = stash.@public;` See the linked question for details (it's about a variable, but you can use this for fields, too). – T.J. Crowder Jan 03 '20 at 11:17
  • 1
    yup that was it, damn it was so simple thanks ! – Nico Walsemann Jan 03 '20 at 11:24

0 Answers0